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


Click here to return to the '10.6: An AppleScript to compress a Finder selection' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: An AppleScript to compress a Finder selection
Authored by: regulus on Mar 04, '11 09:13:11AM
Nice idea about the script however the applescript code isn't clean so I cleaned it up for you. Here's some of the coding issues I saw...
1) you are telling the Finder to perform some tasks that its not needed for which is not a good idea because it can cause slowness and other problems
2) "the selection" is a list of selected items, so coercing to "alias" will not work if more than 1 item is selected
3) there is no error checking
4) a few other small things

I hope this helps.
try
	tell application "Finder"
		set theSelection to the selection
		set selectionCount to count of theSelection
		if selectionCount is greater than 1 then
			error "Please select only one Finder item before running this script."
		else if selectionCount is less than 1 then
			error "Please select one Finder item before running this script."
		else
			set theItem to (item 1 of theSelection) as alias
			set destFolder to (container of theItem) as alias
			set itemName to name of theItem
		end if
	end tell
	
	do shell script ("ditto -c -k --sequesterRsrc --keepParent " & quoted form of POSIX path of theItem & space & quoted form of (POSIX path of destFolder & itemName & ".zip"))
on error theError
	tell me
		activate
		display dialog "Error: " & theError buttons {"OK"} default button 1 with icon stop
	end tell
end try
---
Hank
http://www.hamsoftengineering.com
---
Hank
http://www.hamsoftengineering.com
Edited on Mar 04, '11 09:18:14AM by regulus


[ Reply to This | # ]
10.6: An AppleScript to compress a Finder selection
Authored by: osxpounder on Mar 04, '11 03:11:57PM

Regulus,

Nice of you to try improving this script, but I'm not sure it works properly yet.

When I try to invoke it with Butler, I get a dialog box from Butler with an error, telling me, "Error: Please select only one Finder item before running this script."

I paste your script into a Butler "Smart Item: Applescript." I select several files in Finder. I invoke the Butler item with my chosen abbreviation, "zipem" and see the error dialog box.

I also tried saving your script as an app, and invoking that with Butler, when several files are selected in Finder. I get the same error ("Please select only one file...").

Is there a better way to invoke your script using Butler? How are you doing it?



[ Reply to This | # ]
10.6: An AppleScript to compress a Finder selection
Authored by: regulus on Mar 04, '11 03:22:20PM
I didn't write the basic script code, I just improved it. The author's script only works when you select one file, thus my script works the same. The code can probably be improved to allow more than one item selected. So your problem seems to be that you're selecting several items in the Finder window... that's why I put error handling into the code... the error is telling you the problem... try it on just one item.
---
Hank
http://www.hamsoftengineering.com
Edited on Mar 04, '11 03:25:30PM by regulus


[ Reply to This | # ]
10.6: An AppleScript to compress a Finder selection
Authored by: osxpounder on Mar 04, '11 09:22:13PM

Darn, I misunderstood. I thought you intended your script to handle more than one file. My mistake. Thanks, though!

I found that an Automator action can handle more than one file, but since it strips some metadata, I think I'll stick with using the right-click contextual menu in OS X instead.



[ Reply to This | # ]
10.6: An AppleScript to compress a Finder selection
Authored by: prijker on Mar 05, '11 03:03:56AM

The original script handles several files. I dropped this part of the original code, but you could try to merge this code with mine



[ Reply to This | # ]
10.6: An AppleScript to compress a Finder selection
Authored by: prijker on Mar 04, '11 03:45:55PM

Nice improvment!
It works better than my code and has error handling too.
I'm using it already, thanks



[ Reply to This | # ]