ok, the only thing i know about making a droplet is the on open() part. i have this script which makes use of certain folders. currently, i have to specify which folders i need in the script itself. i want to improve it by being able to drop the folder in and it’ll do the rest. basically i need to know how to get the path of the dropped folder. i’ve messed around and i keep getting the same error which is “Expected a reference”. i wrote this entire (simple) script myself ( sitcom) except of course for the droplet part which i will be learning from here (hopefully).
Model: iBook G4
AppleScript: v2.1 (80)
Browser: Safari v2.0 (412)
Operating System: Mac OS X (10.4)
these_items is a list of the items dropped on the droplet. Acommon mistake is to use these_items as a reference while it is a list. If there are several items dropped, then you usually use a repeat loop to process each item dropped. If the list is supposed to have only one item, then you can just get the first item.
on open(these_items)
set the_reference to first item of these_items
– or
– set the_reference to item 1 of these_items)
– or
– set the_reference to these_items as reference
end open
That’s why you use error handlers and other error checking to specify what you want.
on open (dropped_folder)
set folder1 to item 1 of dropped_folder
display dialog (path of folder1)
tell application "Finder"
get count of folders in folder1
end tell
end open
There are at least a couple of things wrong there. Firstly, ‘display dialog’ wants a string parameter, while the observed parameter is a reference. Next, the scripting addition command is not ‘path of’, but ‘path to’. You can skip a lot of the thinking about ‘path to’. If you already have a reference, then you already have its path or reference by coercing to string. e.g.
set the_item to choose folder
set the_path to the_item as string
or
set the_path to (choose folder) as string
display dialog the_path
‘display dialog’ wants a string. There are several ways to coerce, but the proper way is to use ‘as’. The rest of your simple script should work. When you look at the dictionary, one important thing is the class of the parameters.
on open theFolder
tell application "Finder"
set FolderPath to theFolder as string
set FolderContents to items of folder FolderPath
end tell
repeat with TheItem in FolderContents
display dialog TheItem as string
--any other processes to theItem
end repeat
end open