Help with a script!

I am just learing scripting, so my way of acomplishing this might be rough. When I add image files to certain folders I have folder actions set-up to copy a specific script (on how to deal with the inserted images) into a folder called ••SCRIPTS TO RUN••.

I am trying to create a script to that can be double clicked to go through and run these scripts that have been placed in the folder. Here is what I have:

set theList to {}
set testVar to “”
set i to 1

tell application “Finder”
set theList to the name of every item of folder “OSX:Users:studio:Desktop:BOOKLET IMAGES:••SCRIPTS TO RUN••”
end tell

repeat until i > (count of theList)
set testVar to item i of theList
tell application “Finder” to get the file testVar
set i to i + 1
end repeat

However, I get an error that says that the Finder can’t “get inserts-h.app” (inserts-h.app is the first script in the folder).

After I get this working, I am going to try to get the script to move all the scripts in that folder to the trash, and I would assume that I would just use the “move” command. If there are going to be many issues with that, please educate me.

Thanks in advance for any help given!

Kelly

Hi, Kelly.

The problem you’re having is caused by the fact that in your repeat loop, you’re only giving the Finder the name of each file. It needs to know where on the disk each file is.

tell application "Finder" to get the file testVar of folder "OSX:Users:studio:Desktop:BOOKLET IMAGES:••SCRIPTS TO RUN••"

In that case, of course, you don’t actually need to get the name of each file. You could just get the files themselves:

tell application "Finder"
  set theList to every file of folder "OSX:Users:studio:Desktop:BOOKLET IMAGES:••SCRIPTS TO RUN••"

  repeat with i from 1 to (count theList)
    set testVar to item i of theList -- 'testVar' is now the file itself, rather than its name
    open testVar -- use 'open' to make the Finder 'run' an application file
  end repeat
end tell

However, the Finder’s capable of opening several files at once, so you might find it convenient just to write:

tell application "Finder"
  open every application file of folder "OSX:Users:studio:Desktop:BOOKLET IMAGES:••SCRIPTS TO RUN••"
end

Or:

tell application "Finder"
  open every application file of folder "BOOKLET IMAGES:••SCRIPTS TO RUN••" of the desktop
end

It might be better to get each script to move itself when it’s finished doing its stuff, ending each with something like:

set thisScript to (path to me)
tell application "Finder" to move thisScript to the trash

All the above assumes that the scripts in the folder have been saved as applications. :slight_smile: