Go Back   The macosxhints Forums > OS X Help Requests > AppleScript



Reply
 
Thread Tools Rate Thread Display Modes
Old 06-21-2012, 04:16 PM   #1
mitchmac24
Prospect
 
Join Date: May 2012
Location: TX, United States of America
Posts: 7
Folder Action runs twice

For my work I have to change file extensions... A LOT. Were talking hundreds a day. So I'm trying to make a folder action that will let me drop items into a folder, change it to what I specify and then, ask me where to move the items to (usually the drop box of whomever needs the file.)
I've got the script set up perfectly. My only problem is that when ever I drop a group of files (even just 3, one page Word documents) into the folder, one of them always moves before the others. This makes the folder action run twice. The second run-through will start midway during the first and cancel out the first's dialog boxes and postpone the move command until I quit the second.
Anybody else had this problem? Has anyone found a way to script around this or is there maybe a plist in finder or something I could modify to make them drop at the same time.
Any help would be greatly appreciated!
My mac runs 10.6.8
mitchmac24 is offline   Reply With Quote
Old 06-21-2012, 07:34 PM   #2
NovaScotian
Hall of Famer
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,945
I've never had any luck with the sort of FA you're hoping to run. The second run-through almost certainly starts when you change the file extension -- the Finder views that as a new file in the folder and triggers the FA on it.

What you can do to get around this is to abandon the folder action in favor of a fixed dumb folder and an AppleScript to do what you want to its contents. Either that, or move the file first and then change its name (remember that the extension is part of the name.)
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3
NovaScotian is offline   Reply With Quote
Old 06-22-2012, 03:41 AM   #3
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,040
There are plenty of little free or shareware utilities that will do this well.

Alternatively, you could make an AppleScript droplet app to drag the files onto, rather than a folder with a Folder Action.
benwiggy is offline   Reply With Quote
Old 06-22-2012, 02:47 PM   #4
mitchmac24
Prospect
 
Join Date: May 2012
Location: TX, United States of America
Posts: 7
Thanks NovaScotian for clearing up why that was happening. I didn't know that it checked the name of the contents of the folders to tell when new items were added; I figured it used the item count. And thanks to both of you... I'll mess around with all of your suggestions and see which one I like the best.
mitchmac24 is offline   Reply With Quote
Old 06-22-2012, 06:45 PM   #5
NovaScotian
Hall of Famer
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,945
Folder Actions are a very early construction in AppleScript that relies on the Finder. Benwiggy's suggestion of a droplet is a better way to go (although they can have problems too if you drop too much on at a time. If you've not used one, they go like this example and are saved as an application:

on open these_items -- could be this_Junk; it's up to you.
set the PDFsuffix to "rd1"
repeat with this_item in these_items
set {name:Nm, name extension:Ex} to (info for this_item)
if (Ex is missing value) then set Ex to ""
set Nm to {Nm, Nm's text 1 thru (-2 - (count Ex))}'s item (((Nm contains ".") as integer) + 1)
tell application "Finder" to set name of contents of this_item to (Nm & "." & PDFsuffix)
end repeat
end open
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3
NovaScotian is offline   Reply With Quote
Old 06-22-2012, 10:12 PM   #6
mitchmac24
Prospect
 
Join Date: May 2012
Location: TX, United States of America
Posts: 7
Thank you so much. I could not, for the life of me, figure out how to get a droplet to do this. This is exactly what I needed except for the fact that I need to give different groups of files different new extensions. But that should be as simple as setting a variable named (theVariable) to prompt for a text (where I can type the extension), setting (theReply) to text returned of theVariable, and changing the 2nd line to: set the PDFsuffix to "theReply."
I still don't completely understand droplets so please feel free to let me know if that won't work. Thanks again for your help.

Last edited by mitchmac24; 06-22-2012 at 10:24 PM.
mitchmac24 is offline   Reply With Quote
Old 06-22-2012, 11:12 PM   #7
ganbustein
MVP
 
Join Date: Apr 2008
Location: Berkeley CA USA
Posts: 1,010
Rather than ask for the extension every time, make a separate droplet for each possible extension: one for adding ".txt", one for ".rtf", etc.

Or at least do one for each extension you commonly add, plus one that asks to handle the odd cases.
ganbustein is offline   Reply With Quote
Old 06-23-2012, 11:30 AM   #8
NovaScotian
Hall of Famer
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,945
You can also make it a choose from list so the user doesn't have to type anything and your code doesn't have to check if the entry was a legal extension:

set newExt to (choose from list {"txt", "pdf", "rtf", "doc", "rtfd"} with title "Extension List" without empty selection allowed and multiple selections allowed) as text
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3
NovaScotian is offline   Reply With Quote
Old 06-25-2012, 01:18 PM   #9
mitchmac24
Prospect
 
Join Date: May 2012
Location: TX, United States of America
Posts: 7
Good ideas... thanks so much guys. Ya'll are life savers
mitchmac24 is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 06:29 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.