Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'tar gzip apple script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
tar gzip apple script
Authored by: SOX on Oct 29, '03 01:41:40PM
here is a feeble but not quite working attempt at this

on run
	tell application "Finder"
			set frontWin to folder of front window as string
			set frontWinPath to (get POSIX path of frontWin)
			tell application "Terminal"
				do script with command "(cd \"" & frontWinPath & "\" && tar -czf \"" & frontWinPath & ".tgz\"" & "\"" & frontWinPath & "\")"
			end tell
		on error error_message
			display dialog error_message buttons 
				{"OK"} default button 1
		end try
	end tell
end run
THIS DOES NOT WORK QUITE RIGHT. there are two problems. first frontWindowPath has a termnal "/" character which means I cant just concatenate ".tgz" to the end of it to create the archive name. some how I have to strip that tail "/" from the path name, but I dont know how to do this in applescript.

the second problem is that it's overkill to fire up a new terminal window to do its job: but that's only because I dont know how to just execute a unix command within apple script directly.

note that the "cd" command I execute is superfluous to the archive command. However it serves the purpose of testing to see if the directory you slected has an executable permission for you. the && comand guarentees that if the cd command fails the tar command is aborted.

if this worked correctly--and it does not-- it should allow you to select a folder in the finder and click the apple script to archive it.

[ Reply to This | # ]