OK, I fixed my own problem…
But I still have to know – why does the first script work and the second one doestn’t?
Here’s the first script:
property desktopPath : path to desktop
try
tell application “Finder”
make new folder in the desktop with properties {name :“Converted Items”}
set targetFolder to (desktopPath & (“Converted Items:” as text ) as string )
end tell
on error theError
display dialog “There is already a Converted Items folder on the desktop. Do you want to continue?” buttons {“Cancel”, “OK”} default button 2
set targetFolder to (desktopPath & (“Converted Items:” as text ) as string )
end try
And here is the script that doesn’t work:
try
tell application “Finder”
make new folder in the desktop with properties {name :“Converted Items”}
set targetFolder to ((path to desktop ) as text ) & (“Converted Items:” as text ) as alias
end tell
on error – ‘Converted Items’ exists on the desktop
display dialog “There is already a Converted Items folder on the desktop. Do you want to continue?” buttons {“Cancel”, “OK”} default button 2
set targetFolder to ((path to desktop as text ) & (“Converted Items:” as text ))
end try
Thanks in advance,
Tom
[These scripts were automatically tagged for color coded syntax by Convert Script to Markup Code ]
It looks like there is some terminology conflict. The “path to” command comes from Standard Addtions, and the Finder doesn’t seem to like it:
tell application "Finder"
path to desktop --> error "Finder got an error: Can't make desktop into a item."
end tell
However, the “path to” command isn’t needed when your inside a Finder tell statement:
tell application "Finder"
desktop folder --> this is the Finder's terminolgy
end tell
Thanks! That helps a lot…
This also works – I guess it wants desktop folder, instead of desktop…
–Tom
try
tell application “Finder”
make new folder in the desktop with properties {name :“Converted Items”}
set targetFolder to (path to desktop folder as text ) & (“Converted Items:” as text ) as alias
end tell
on error – ‘Converted Items’ exists on the desktop
display dialog “There is already a Converted Items folder on the desktop. Do you want to continue?” buttons {“Cancel”, “OK”} default button 2
set targetFolder to ((path to desktop as text ) & (“Converted Items:” as text ))
end try
[This script was automatically tagged for color coded syntax by Convert Script to Markup Code ]
jonn8
June 1, 2004, 9:47pm
#4
I find it’s better to check if the folder exists first to see if there is a conflict as opposed to waiting for the Finder to tell me there’s a conflict. In some versions of Mac OS, it will create an untitled folder and then try to rename it leaving you with unwanted folders. this solves that by switching the order of operations:
–Open this script in a new Script Editor window.
try
set targetFolder to ((path to desktop as text ) & “Converted Items:”) as text
get targetFolder as alias
display dialog “There is already a Converted Items folder on the desktop. Do you want to continue?” buttons {“Cancel”, “OK”} default button 2
on error
tell application “Finder” to make new folder at desktop with properties {name :“Converted Items”}
end try
Oh, as it says in the Finder dictionary, I always use “at” instead of “in” for making new items. I didn’t even know “in” would work.
Jon
[This script was automatically tagged for color coded syntax by Convert Script to Markup Code ]
Thanks for the tip!
Did you ever get the feeling that AppleScript is like the martial arts? You must continue to learn, grasshopper – unless you are Matt Neuberg, or Paul Berkowitz, or a couple of other people…
I can hear it now, “Matt Neuberg is the Bruce Lee of AppleScript!”
–Tom