• 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: Thu, 25 Aug 2005 12:23:44 -0700

On Aug 25, 2005, at 7:43 AM, patrick machielse wrote:

Op 25-aug-2005, om 16:04 heeft applescript-users- email@hidden het volgende geschreven:

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

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.

So (at least on Tiger) I could test like this:

    on run argv
        if argv = me then
            -- not started from the command line

Somehow that scares me...

That should work on pre-Tiger systems as well. Yes, it's completely undocumented behavior, but it's completely undocumented behavior in a version that's already shipped, so it's unlikely to change. =)


As it happens I only need to branch in my script if an argument was passed on the command line, so I think I can get away with testing like so:

    on run argv
        if (class of argv = list) and ((count of argv) > 0) then
            -- use the argument
        else
            -- use 'try' around gui code and catch errors

Still, this is probably better. It's generally safer to test for what is, rather than not what ain't.


2. There are other ways for your script to be run without interaction
allowed; running from osascript is merely the most common one. ...
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.

If I understand you correctly: If I have an application that sets LSUIElement 1 in its Info.plist, display dialog will fail if it tries to execute that in an AppleScript file? Nice.

Actually, LSUIElement would work. That's the definition of a UI element: an application that doesn't show up in the Dock, but still has visible UI. If you'd said LSBackgroundOnly, you'd have been correct.



--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: finding out the name of the script file
  • Next by Date: Re: on idle() handler in script object
  • Previous by thread: Re: [newby] Detect if a script was started from the command line
  • Next by thread: Folder action to rename files
  • Index(es):
    • Date
    • Thread