I am trying to use this thread to make a folder action script that changes the default application for the file to Apple Preview.
I have this:
on adding folder items to this_folder after receiving dropped_items
set listofextensions to {"pdf", "jpg", "tif", "tiff"}
tell application "System Events"
repeat with this_item in dropped_items
repeat with extcheck in listofextensions
if (this_item as text) ends with extcheck then
set default application of file (this_item as text) to (path to application "Preview")
exit repeat
end if
end repeat
end repeat
end tell
end adding folder items to
Before I added the test repeat to check what type of file was being dropped into the folder, the default application change worked fine. But of course I do not want all types of file changed to default to Preview. After I added the repeat test, the script fails to work.
property listofextensions : {"pdf", "jpg", "tif", "tiff"}
on adding folder items to this_folder after receiving dropped_items
tell application "System Events"
repeat with this_item in dropped_items
if name extension of this_item is in listofextensions then
set default application of file (this_item as text) to (path to application "Preview")
end if
end repeat
end tell
end adding folder items to
I write a script (Clorox File Repair) that restores the File Type and File Creator of files that lose their resource fork, usually from landing on a PC without an AppleTalk stack, or from being compressed into things like TAR. This is the behavior the OS exhibits in my experience when missing File Type and File Creator:
–Tries to use the file extension as a basis to guess what app to use, then uses the “Open with” defaults
–Without extension, the Mac OS seems to have some limited ability to peek inside a file’s header to take a guess.
Problem is, it’s a lousy guesser at both. For example, all “EPS” files must be Photoshop files…couldn’t be Illustrator after all.
So Clorox File Repair uses hard-coded detection routines that are more accurate, and when it fixes File Type, Creator, and sometimes the extension, the Mac OS wil treat the file as such:
–If the Creator is available, launch that application
–If the Creator is unknown, use the “Open with” choice
So by all that I know, simpy changing the Creator Type should fix the problem of the OP unless I misread. In other words, write a script that changes the Creator Type and double-click to your heart’s content.
Is this not 100% true in Leopard anymore and somehow I’ve just randomly avoided the issue?
Otherwise using “set creator type of to <4 character creator code> as text” solves the problem handily…
Many thanks. Works well. Although I am a little suspicious of Folder Action Scripts as I find them to be erratic in real time operation. Still, while it works:)…
You can test Folder Action scripts by commenting out the event handler lines
and adding a line to specify the files. Then you get error messages, if something fails
property listofextensions : {"pdf", "jpg", "tif", "tiff"}
set dropped_items to choose file with multiple selections allowed
-- on adding folder items to this_folder after receiving dropped_items
tell application "System Events"
repeat with this_item in dropped_items
if name extension of this_item is in listofextensions then
set default application of file (this_item as text) to (path to application "Preview")
end if
end repeat
end tell
-- end adding folder items to