Saturday, February 18, 2012

Run Bash file in Finder in Terminal with Easy Automator Service

You can create a Automator service to run bourne script files (bash) from Finder with a simple right click. This service will open a new Terminal window and execute whatever bourne script you like. It can be modified to run other scripts in terminal.

Step 1: Open Automator and select service


Step 2: see image and pay attention to the red annotations


Applescript Text for copying:
on run {input, parameters}
set thescriptFile to quoted form of POSIX path of (input as string)
(*
--quoted form adds '' around thescriptFile
--without POSIX Path it looks like 'Macintosh HD 2:Jonathan:Scripts:Bash:backup system:macbookair_backup_odd.sh'
--with POSIX path of quoted form it looks like /'Macintosh HD 2:Jonathan:Scripts:Bash:backup system:macbookair_backup_odd.sh'
--CORRECT with quoted form of POSIX path it looks like 'Macintosh HD 2:Jonathan:Scripts:Bash:backup system:macbookair_backup_odd.sh'
*)
tell application "Terminal"
activate
do script "sh " & thescriptFile & "; 8"
end tell
say "Making backup in new terminal window"
end run

Step 3: right click a bash file (must be an executable bash script [chmod a+x the file from terminal--i have another automator service for that])

No comments:

Post a Comment