I’m back to scripting after years and need some help.
Here’s my question.
I need to instruct a script working as an applet to do complex processing of text files (located on a server) I drag on it whose name and number varies in time.
Testing it I wrote out the name of the file at the beginning of the script:
set thePath to /Volumes/ServerQT/LAVORAZIONE/TESTI/TestiAlmanacco/Mostre/FbApronoItalia.xtg
but when I ask it to “set thePath to selection as string” it returns a useless
That does not compile. If it’s a string it needs quotes. If it’s something Finder might know about it could look like this:
set thePath to alias "ServerQT:LAVORAZIONE:TESTI:TestiAlmanacco:Mostre:FbApronoItalia.xtg"
Who are you asking? The script? Finder?
For ‘selection’ Finder will return a list of references, not a path string.
Please post a code snippet, so we can see what’s going on.
@alastor933
Thank you for your reply.
Sorry for missing quotes in example 1.
Here’s the script snippet in its working form. It does the job when I launch it:
on open
tell application "Finder"
set thePath to "/Volumes/ServerQT/LAVORAZIONE/TESTI/TestiAlmanacco/Spettacoli/CinemaItalia.xtg"
end tell
tell application "Tex-Edit Plus"
open thePath
-- script follows
end tell
end open
What I am trying to do is to have it to work with any file, regardless of its name and location, I mean to work “universally”.
That’s why I tried to tell the Finder to set “thePath” to “selection”, the latter being the file I will drag on the applet for processing.
That’s not how a droplet operates. It works like so:
on open (theItems)
-- useful code goes here
end open
‘theItems’ is a list of (Finder) references, so you need a loop to process them - even when you dropped only one item.
Have Finder open the item, it should open in its default application.
(Note that Finder does not understand POSIX (slashes): it uses HFS (colons) exclusively.)
When you doubleclick such a file, does it open in Tex Edit?
Do you want to process files belonging to other applications, or only xtg files?
Anyway, this would be the skeleton for a droplet to process Tex Edit files:
on open (theItems)
-- file type test here?
repeat with anItem in theItems
tell application "Tex-Edit Plus"
open anItem
-- script follows
end tell
end repeat
end open
Sorry for the misassertion. They’ve always been aliases in the past. ASLG still says they’re aliases. ‘bookmark’ isn’t an AppleScript type. There’s no mention of ‘bookmarks’ or «class bmrk» in any of the AS release notes from 10.0 to 10.6.
All that notwithstanding, I do accept of course that they are what’s now passed to ‘open’ handlers. Fortunately, they seem to behave exactly like aliases and can therefore mostly be ignored.
In 10.6 Apple introduced a new URL based specifier “bookmark data” which is encapsulated in a NSData object.
Although it’s not well documented Apple changed a few things while implementing the AppleScriptObjC bridge.
I guess bookmark data is supposed to replace the old AliasHandle type in the future.
The argument of the on open handler in 10.6.x and higher is a list of bookmark data objects.
ScriptDebugger treats bookmark data silently as alias, Script Editor does not.
For portability and reliability I recommend to coerce the bookmark data items to alias