• 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: [newby] Detect if a script was started from the command line
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [newby] Detect if a script was started from the command line


  • Subject: Re: [newby] Detect if a script was started from the command line
  • From: Christopher Nebel <email@hidden>
  • Date: Wed, 24 Aug 2005 14:14:25 -0700

On Aug 24, 2005, at 10:01 AM, patrick machielse wrote:

Op 24-aug-2005, om 18:22 heeft applescript-users- email@hidden het volgende geschreven:

Your way of detecting running via osascript(1) is fairly clever, but
consider:

1. It'll only work in Tiger and later, since before then, osascript
(1) didn't pass arguments to the script.

My script is intended for use with Mail 2, so I know it will be used on Tiger.
Would the construct


    on run arguments
        if (class of arguments = list) then
        ...

cause problems on Panther?

Not problems, precisely, but it won't give you the answer you want, since in Panther, "arguments" won't be a list. (Weirdly, in osascript it appears to wind up getting set to the handler itself!) You could reverse the sense of the test and check for "class ≠ script"...


Also, if I run from the Script Editor I see that the class of arguments is 'script'. How should I interpret that?

It means that "arguments" is a script object. As it happens, it's the top-level script object, the same thing as "me" in that context.


2. There are other ways for your script to be run without interaction
allowed; running from osascript is merely the most common one.

I'm interested to know any other scenario's (executing over a network connection?)

I'll admit that this is more a theoretical case than an actual one. An application can request to not have any user interaction when running a script, or it could implicitly be forced to do that because it's background-only, but almost no one does that -- osascript is one of the only cases.


In any case, it's good practice to ask the question you really want the answer to. In your case, that's "can I present UI?", and the official way to answer that is to use the "(don't) interact" bit.


--Chris Nebel AppleScript and Automator Engineering

_______________________________________________
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


References: 
 >Re: [newby] Detect if a script was started from the command line (From: patrick machielse <email@hidden>)

  • Prev by Date: Re: run script from browser
  • Next by Date: Re: run script from browser
  • Previous by thread: Re: [newby] Detect if a script was started from the command line
  • Next by thread: Re: [newby] Detect if a script was started from the command line
  • Index(es):
    • Date
    • Thread