Some Useful AppleScripts

Discussion in 'PowerPC Macs' started by AmazingHenry, Nov 13, 2016.

  1. AmazingHenry, Nov 13, 2016
    Last edited: Nov 14, 2016

    AmazingHenry macrumors 65816

    AmazingHenry

    Joined:
    Jul 6, 2015
    Location:
    Central Michigan
    #1
    EDIT: Made a Spotlight script with the help of @eyoungren and @Intell. Thanks for your help!
    Before reading: This isn't specifically PowerPC related but these only work on PowerPC, and they're made to help out with PowerPC projects, so I'll post them here. Anyway, on to the main post!

    So, I've made a little collection of AppleScript applications for PPC (yes, I know and love AppleScript). I have no idea what they'll be used for but I think they might help with things like the Sierra theme or the Ultimate Leopard DVD. They also might help speed up your Mac. Anyway, there are AppleScripts for disabling/enabling these things:
    -2D Dock
    -Hidden files in Finder
    -Dashboard
    -Spotlight

    All of these have been tested and are working perfectly. That said, if something does go wrong and you hose your system, I'm not responsible. EDIT: The Spotlight one is untested.

    Anyway, these all run Terminal commands and a graphical interface is often easier than typing a command into Terminal.

    Also, I was trying to do a Spotlight one but that Terminal command requires a password (it uses sudo) so my AppleScript gives an error. And the "with administrator privileges" command doesn't work on Leopard as far as I can tell. Could an AppleScript expert perhaps help out? Thanks. EDIT: As said above, Intell and eyoungren have assisted me in making a Spotlight script.

    Anyway, I hope you enjoy these and I hope they make your life easier. I'll update the post and the download over time with new scripts, hopefully. Thanks for reading this!
     

    Attached Files:

  2. eyoungren macrumors P6

    eyoungren

    Joined:
    Aug 31, 2011
    Location:
    Online
    #2
    For shell scripts with passwords, do this:

    Code:
    do shell script "your command" password "your password" with administrator privileges
    Where 'your command' is the command you are executing and 'your password' is the password of the current logged in account (assuming it's an admin account). The downside to this is that if you aren't careful passing the script around you can reveal your password to others.

    If that doesn't work, let me know. It's part of an old script. I'm at home right now but I use shell scripts for things at work all the time. So, I'll grab copy from there if this does not work.

    PS. One of those G4s in the recent pics I posted is an Applescript server. Bunch of scripts that go off to process editorial photos and move files around the server depending on where they need to go. My photo processing script calls Growl and Graphic Converter which processes all photos silently (never visible on screen).

    I have older scripts that can open PDFs inside Acrobat and save them out as EPS files (silently, you never see the open file on screen) as well as some other stuff.

    One script I use daily relies on Quicksilver (the quick launcher) to trigger a script that copies ad proofs to our sales server.
     
  3. Intell macrumors P6

    Intell

    Joined:
    Jan 24, 2010
    Location:
    Inside
    #3
    You can leave out the "password "your password" part and it'll prompt you for your password in a standard OS X password prompt.
     
  4. eyoungren macrumors P6

    eyoungren

    Joined:
    Aug 31, 2011
    Location:
    Online
    #4
    But if it's a script you want to fire off with no interaction on your part?
     
  5. Intell macrumors P6

    Intell

    Joined:
    Jan 24, 2010
    Location:
    Inside
    #5
    Then you would have to include the "password" part in the script.
     
  6. AmazingHenry thread starter macrumors 65816

    AmazingHenry

    Joined:
    Jul 6, 2015
    Location:
    Central Michigan
    #6
    Yeah, I can't include the password because these are meant to work on different Macs. I need a password prompt.
     
  7. AmazingHenry thread starter macrumors 65816

    AmazingHenry

    Joined:
    Jul 6, 2015
    Location:
    Central Michigan
    #7
    Wow, putting "with administrator privileges after the command worked. I thought it had to look like this:

    with administrator privileges
    do shell script "script goes here"

    But I actually had to do this:

    do shell script "script goes here" with administrator privileges

    Now it prompts me for a password with the standard OS X password prompt, as @Intell said above. Thanks! I'll have a Spotlight script added soon!
     
  8. eyoungren, Dec 8, 2016
    Last edited: Dec 8, 2016

    eyoungren macrumors P6

    eyoungren

    Joined:
    Aug 31, 2011
    Location:
    Online
    #8
    Forgot about this until today. Wanted to get back to it with the code for the script I use to convert images.

    Below is the code, but before I paste it in I'll explain it a little.

    The script calls three apps. First off, it calls Play Sound, which is simply an app that plays a specified sound when the script is triggered. Since the G4 this script runs on is headless and I am not always looking at Chicken of the VNC this audio cue is important. It alerts me that images are being processed.

    Second, the script calls Growl to display a VISUAL onscreen notification. That takes a slight second to come up so I can usually verify that this is indeed what is happening by looking at CotVNC after I heard the sound.

    Finally, the script calls Graphic Converter which does the actual work. It tells GC to process all images in the folder the script is attached to using a batch file that has been precreated.

    That's pretty much it. There is an error routine in there I believe, but it's been a while since I actually looked at the code.

    PS. The script does this all quietly in the background too. Nothing shows on the screen.

    Code:
    -- property trig_folder : "Pueblo3:Users:erik.youngren:Desktop:Folder Action Scripts:" as alias
    property source_folder : "PHOTO (ppsbsserver):CMYK_IN:" as alias
    property dest_folder : "EDITORIAL (ppsbsserver):CCX_DO NOT DELETE" as alias
    property error_folder : "PHOTO (ppsbsserver):ERROR:CMYK:" as alias
    property batch_file : "Pueblo3:Users:erikyoungren:Library:Application Support:GraphicConverter:Actions:CMYK" as alias
    
    on adding folder items to this_folder after receiving added_items
    	tell application "Play Sound"
    		play "Pueblo3:System:Library:Sounds:Glass.aiff"
    	end tell
    	growlAlert()
    	convertIt(source_folder)
    end adding folder items to
    
    on growlAlert()
    	tell application "GrowlHelperApp"
    		-- Make a list of all the notification types 
    		-- that this script will ever send:
    		set the allNotificationsList to ¬
    			{"Photo Server"}
    		
    		-- Make a list of the notifications 
    		-- that will be enabled by default.      
    		-- Those not enabled by default can be enabled later 
    		-- in the 'Applications' tab of the growl prefpane.
    		set the enabledNotificationsList to ¬
    			{"Photo Server"}
    		
    		-- Register our script with growl.
    		-- You can optionally (as here) set a default icon 
    		-- for this script's notifications.
    		register as application ¬
    			"Growl Photo Server" all notifications allNotificationsList ¬
    			default notifications enabledNotificationsList ¬
    			icon of application "Script Editor"
    		
    		--	Send a Notification...
    		notify with name ¬
    			"Photo Server" title ¬
    			"Photo Server" description ¬
    			"Photos are now being processed" application name "Growl Photo Server"
    		
    	end tell
    end growlAlert
    
    on convertIt(fda)
    	-- tell application "Finder"
    	--	open file "Trigger Photo.app" of trig_folder
    	-- end tell
    	tell application "Finder"
    		activate
    		set this_item to every file of fda
    		repeat with one_item in this_item
    			try
    				tell application "GraphicConverter"
    					convert file (one_item as file specification) using batch (batch_file as file specification) to folder (dest_folder as file specification)
    				end tell
    			on error the error_message number the error_number
    				set the error_text to "Error: " & the error_number & ". " & the error_message
    				-- the following line evokes the sub-routine to write the error into an error log created on the desktop
    				-- if the file "Script Error Log.txt" already exists, it will add one line to the log
    				my write_error_log(the error_text)
    				move it to error_folder with replacing
    			end try
    		end repeat
    	end tell
    end convertIt
    
    on write_error_log(this_error)
    	set the error_log to ((errorFolder) as text) & "Script Error Log.txt"
    	try
    		open for access file the error_log with write permission
    		write (this_error & return) to file the error_log starting at eof
    		close access file the error_log
    	on error
    		try
    			close access file the error_log
    		end try
    	end try
    end write_error_log
    --- Post Merged, Dec 8, 2016 ---
    Oh yeah!

    I suppose I should mention that some of the commands in the script reference an Applescript addon called Jon's Commands.

    Jon's Commands works on both OS9 and OS X. I use these commands because the standard method of copying, moving and deleting files under Applescript assumes that you are NOT operating over a network and therefore do not have to deal with delete confirmation boxes - which kill the script.

    Jon's Commands enables you to delete files directly with no confirmation on network shares. Including over SMB on files stored on an NTFS formatted hard drive.

    I have found it to be an excellent tool.

    Documentation here: http://www.seanet.com/~jonpugh/JonsCommandsDocs.html
     
  9. MysticCow macrumors 6502a

    MysticCow

    Joined:
    May 27, 2013
    #9
    Now, no AppleScript collection is complete without Damned, The AppleScript From Hell. PM me for the copy and explanation.
     
  10. hellothere231 macrumors regular

    Joined:
    Sep 13, 2012
    #10
    Huh, why the name "The AppleScript From Hell"?
     
  11. MysticCow macrumors 6502a

    MysticCow

    Joined:
    May 27, 2013
    #11
    Because it is what it is. It's the most non-destructive hellish AppleScipt ever made.
     

Share This Page