Sunday, November 27, 2022

#1 2003-04-23 09:31:46 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336


The tell statement has always given annoyances to Applescript programmers. You usually want to locate an App by Creator, and to  have compact, fast and reliable code across various machines and OSes.  I  used this pathToCREA handler for years in many scripts, in order to satisfy these needs.

OS version: Classic


on pathToCREA(theCrea) -- use as "tell application pathToCREA("Crea")"
   if length of theCrea is not 4 then error "•Can't get application file id \"" & theCrea & "\" into a item." number -1700 -- Mimics Finder behaviour
   tell application "Finder" to set theProcess to {} & (every process whose creator type is (theCrea as type class)) -- old versions of scriptable Finder don't like "first process", while "every process" is OK
   tell application "Finder"
       if theProcess is {} then
           if exists application file id theCrea then
               return application file id theCrea as alias as string -- find the Application full path based on its Creator Code. Double coercion necessary for getting the correct Disk for Desktop items
               error "•Can't get application file id \"" & theCrea & "\"." number -1728 -- Mimics Finder behaviour
           end if
       else -- process running
           return (file of first item of theProcess) as alias as string
       end if
   end tell
end pathToCREA

-- examples
-- single compact statement
tell application pathToCREA("MSIE") to «event WWW!OURL» "[url][/url]"

-- deferred tell
set Internet_Explorer to pathToCREA("MSIE")
-- some preprocessing here
tell application Internet_Explorer
-- I.E. specific statements
end tell

One mans trash is another mans treasure

Filed under: Finder



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)