• 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 09:14:52 -0700

On Aug 24, 2005, at 2:06 AM, patrick machielse wrote:

I whipped up a script that _might_ be started from the command line. I believe that if it is started in this way I cannot have any user interaction, (I couldn't find any reference to 'command line' or osascript in the AppleScript Language Guide (anno 1999). Maybe I should file a bug...) so if the script is launched using osascript I want it to not use any dialogs.

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.

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

If interaction isn't allowed, commands that try to interact will throw an error, which you can catch and handle with a "try" block. For example:

    try
        display dialog "Hello, world!"
    on error e
        return "You must be running this from Terminal.  " & e
    end try

Run using Script Editor, you get the dialog; run using osascript(1), you get the output "You must be running this from Terminal. No user interaction allowed." If you just want to ignore the error, use "try ... end try", without any "on error" part.


--Chris Nebel AppleScript and Automator Engineering

P.S.: As for the Language Guide not mentioning osascript, well naturally -- Mac OS X didn't exist in a public form when the ASLG was last updated. =) Go ahead and file a bug on that, though (mentioning osascript, not the general need to update it), so that way it won't get lost.
_______________________________________________
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: 
 >[newby] Detect if a script was started from the command line (From: patrick machielse <email@hidden>)

  • Prev by Date: on idle() handler in script object
  • Next by Date: Re: Folder action to rename files
  • Previous by thread: [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