• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSAppleScript: Compiling a script launches an application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSAppleScript: Compiling a script launches an application


  • Subject: Re: NSAppleScript: Compiling a script launches an application
  • From: Christopher Nebel <email@hidden>
  • Date: Fri, 29 Jul 2005 11:53:33 -0700

The nominally correct list for this would have been applescript-implementors, but whatever.

The others are correct: AppleScript must fetch the terminology of an application to compile a script against it, and applications are allowed to say that their terminology is "dynamic", that is, "launch me and send me a request, and I'll tell you what it is."  (Why iTunes is flagged this way is a minor mystery to me; I thought it used to not be.)

I should point out that compiling and executing a short script from raw source, as NSAppleScript requires you to do, is a woefully inefficient use of system resources.  It would be much less work for the system if you simply sent the necessary Apple events yourself.  However, it's also much *more* work for you to code, and there isn't any easy way to reduce that (yet).


--Chris Nebel
AppleScript and Automator Engineering

On Jul 29, 2005, at 6:01 AM, Alexander von Below wrote:

I am usually a Cocoa coder, and have noted something that seems odd to me: If the following file is compiled by an NSAppleScript object (either explictly or upon first execution), iTunes is launched:


tell application "System Events"
    if exists process "iTunes" then
        tell application "iTunes"
            if player state is playing then
                set x to name of current track & "    " & artist of current track
                return x
            else
                return "No"
            end if
        end tell
    else
        return "No"
    end if
end tell

All subsequent executions of the script work as expected (i.e. not launching iTunes if it is not running)

If the script is modified like this:

tell application "System Events"
    if exists process "iTunes" then
        return "Yes"
    else
        return "No"
    end if
end tell

Everything works as expected again.

The nominally correct list for this would 
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSAppleScript: Compiling a script launches an application
      • From: Alexander von Below <email@hidden>
References: 
 >NSAppleScript: Compiling a script launches an application (From: Alexander von Below <email@hidden>)

  • Prev by Date: Re: [OT] "Message" when file created.
  • Next by Date: Re: NSAppleScript: Compiling a script launches an application
  • Previous by thread: Re: NSAppleScript: Compiling a script launches an application
  • Next by thread: Re: NSAppleScript: Compiling a script launches an application
  • Index(es):
    • Date
    • Thread