i have script for create temp folder inside chosen folder
property myTitle : "Convert Illustrator layers to TIFF"
property buttonCancel : "Cancel" as text
property buttonOk : " Ok " as text
on run
set outputFolder to (choose folder with prompt "Select location for output files:") as string
try
tell application "Finder"
if (exists folder ((outputFolder as string) & "Temp")) then
tell me
activate
display dialog "Folder already exists"
end tell
set tempFolder to folder ((outputFolder as string) & "Temp")
else
tell me
activate
display dialog "Folder don't exists"
end tell
set tempFolder to make new folder at (outputFolder as string) with properties {name:"Temp"}
end if
end tell
on error the error_message number the error_number
tell me
activate
display dialog "Error in Dropped Items: " & the error_number & ". " & the error_message ¬
buttons {"OK"} default button 1 with icon stop with title myTitle
end tell
end try
tell me
activate
display dialog "Temp folder - " & tempFolder as text
end tell
end run
At the first run all work well, if temp folder don’t exists, finder make new folder. At the next run If folder already exists, finder set properly existing temp folder.
Then i delete temp folder in finder window and try to start script “ script count missing temp folder as already exists, and got an error “Can’t get folder”…
If i run a script again, all work well, finder don’t look a missing folder.
I’m still rereading your post, but it sounds like a path reference or alias reference which looks something like this:
First note that the name “TestFolder” should be followed by a colon. Now, with an alias reference, if you drag the folder to the Trash, the alias reference to the TestFolder will change to point to the trash. Hence, the folder still exists. Alias references follow files and folders where you place them. Try emptying the trash after you place the folder in it.
Here I tested with outputFolder being the Desktop folder and everything behaved flawlessly.
I assume that you used an other folder and that the lazy “guy” named Finder didn’t updated its own infos before you run the script after deleting the folder.
try to add one instruction :
tell application “Finder” update folder outputFolder # ADDED
if (exists folder ((outputFolder as string) & “Temp”)) then
I assume that with this one you will no longer get the described behavior.
I wish to add two comments :
(1) As you coerce the alias returned by choose folder into a string in the first instruction, it’s waste of time to ask for the coercion in every other instructions.
(2) I was quite sure that the instruction supposed to create the folder will fail because you are asking the Finder to create a new folder in a string. Finder is fair enough to treat the string as a folder identifier but I think that it would be better to no longer rely upon this behavior and code :
set tempFolder to make new folder at folder (outputFolder as string) with properties {name:“Temp”}
Here is a version edited according to my comments :
property myTitle : "Convert Illustrator layers to TIFF"
property buttonCancel : "Cancel"
property buttonOk : " Ok "
on run
set outputFolder to (choose folder with prompt "Select location for output files:") as string
try
tell application "Finder"
update folder outputFolder
if exists folder (outputFolder & "Temp") then
tell me
activate
display dialog "Folder already exists"
end tell
set tempFolder to folder (outputFolder & "Temp")
else
tell me
activate
display dialog "Folder don't exists"
end tell
set tempFolder to make new folder at folder outputFolder with properties {name:"Temp"}
end if
end tell
on error the error_message number the error_number
tell me
activate
display dialog "Error in Dropped Items: " & the error_number & ". " & the error_message ¬
buttons {"OK"} default button 1 with icon stop with title myTitle
end tell
end try
tell me
activate
display dialog "Temp folder - " & tempFolder as text
end tell
end run
Yvan KOENIG (VALLAURIS, France) mardi 13 mai 2014 18:35:07