Applet processing

Hi there.

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

"ServerQT:LAVORAZIONE:TESTI:TestiAlmanacco:Mostre:FbApronoItalia.xtg"

Last but not least, it opens the file as TextEdit. How can I force it to be opened as a Tex-Edit Plus one?

Any suggestion?

Thank you in advance

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.

Tell your target app to open it, not Finder.

@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”. :slight_smile:
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.

Again, thank you for your help

To return the path with the forward slashes “/” rather than colons “:”, have you tried

set thePath to POSIX path of selection

or take thePath as returned and convert it to POSIX path

set thePath to "ServerQT:LAVORAZIONE:TESTI:TestiAlmanacco:Mostre:FbApronoItalia.xtg"
set posPath to POSIX path of thePath

Drop a readable TE Plus file onto this droplet:


on open ff
	tell application "Tex-Edit Plus" to open ff
end open

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

Thank you all.

I will read your replies carefully and test the Scriplets.

I will keep you posted about the results.

Everything works fine. :smiley:

alastor933’s script skeleton does the job seamlessly.

@intoto @Eelco Houwink
Thank you for your suggestions. I learned a lot from it.

'theItems is a list of alias(es). :slight_smile:

…except when they’re bookmarks:

on open {afile}
	display dialog (class of afile) as text
--> «bkmk»
end open

:slight_smile:

Hi, Shane.

→ «class bmrk».

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. :wink: Fortunately, they seem to behave exactly like aliases and can therefore mostly be ignored.

technical explanation:

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

Yes, it’s pretty poor. My guess is that the AS team were simply caught unawares.

Yes – with the emphasis on mostly. Some apps don’t like them, so sadly Stefan’s advice about coercing is sometimes needed.