• 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: Variables and command-line args
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Variables and command-line args


  • Subject: Re: Variables and command-line args
  • From: Philip Aker <email@hidden>
  • Date: Mon, 02 Jun 2008 11:53:15 -0700

On 08-06-02, at 11:09, Kevin Walzer wrote:

I'm trying to pass an argument to an AppleScript from the command line, but keep running into problems with scope. Here's a simple example:

property myName : [] --initialize the variable

on run args
set item 1 of args to myName -- pass the value of arg 1 to myName
return myName
end run

I run this script in Terminal with this command:

osascript name.applescript Name

I expect to get the value "Name" as output. Instead, I get a blank line, apparently because I have set the value of myName to [] when defining it as a property.

I thought that setting myName as a property would make it global in scope, and that the value could be reset from within a handler. How can I pass the value of arg 1 to the myName variable?

property some_name : "bob"

on run theArgList
set n to item 1 of theArgList
return n & " and " & some_name
end run

osascript args.applescript betty

--> betty and bob


Philip Aker
echo email@hidden@nl | tr a-z@. p-za-o.@

Democracy: Two wolves and a sheep voting on lunch.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Variables and command-line args (From: Kevin Walzer <email@hidden>)

  • Prev by Date: Re: background color
  • Next by Date: Re: background color
  • Previous by thread: Re: Variables and command-line args
  • Next by thread: Calling a nib item from AppleScript (and more..)
  • Index(es):
    • Date
    • Thread