Again Applescript Error -10006

I recorded this script:


tell application "Finder"


activate

set target of Finder window 1 to folder "Documents" of folder "vittorio" of folder "Users" of startup disk

set target of Finder window 1 to folder "COMMISSIONE TRIBUTARIA" of folder "Documents" of folder "vittorio" of folder "Users" of startup disk

set target of Finder window 1 to folder "COMM. TRIB. MIA" of folder "COMMISSIONE TRIBUTARIA" of folder "Documents" of folder "vittorio" of folder "Users" of startup disk

open document file "TESTBatchRun.ffs_batch" of folder "COMM. TRIB. MIA" of folder "COMMISSIONE TRIBUTARIA" of folder "Documents" of folder "vittorio" of folder "Users" of startup disk using application file "RealtimeSync.app" of folder "FreeFileSync_6" of folder "Applications" of startup disk

end tell

Well, I added to the recorded script the last row (open document file etc.)

Now, if I run this script with a finder window on the desktop it works fine, while if I run the script whit Finder not open it returns the following error:

error "Finder" found an error:can't set Finder window 1 to folder \"Documents\" of folder \"Vittorio\" of folder \"Users\" of startup disk." number -10006 from Finder window 1

(error "Finder ha trovato un errore: Non posso impostare Finder window 1 a folder \"Documents\" of folder \"Vittorio\" of folder \"Users\" of startup disk." number -10006 from Finder window 1)


How can I avoid rising the error when the script run even if no finder window open?


Thanks a lot


Applescript editor 2.6.1, Applescript 2.3.2 on iMac 21,5" running OS X 10.9 Mavericks

Posted on Jun 28, 2014 7:11 AM

Reply
6 replies

Jun 29, 2014 10:23 AM in response to Vittorio

If I understand what you're trying to do, you want something like the following:


tell application "Finder"

if (count of Finder windows) = 0 then


-- no windows open, so open the documents window

open folder "Documents" of home

else


-- otherwise retarget the first window

set target of first Finder window to folder "Documents" of home

end if

end tell

-- edit: used the wrong code first time around. sorry.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Again Applescript Error -10006

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.