Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Replace variable with answer in Applescript

Hello,


I was wondering whether it is possible to replace (x or y) with an answer that is recieved via dialog box.


I have a command: [sudo ifconfig en1 ether (x)] X=Mac Address


I know that the script would look like


tell application "Terminal"

do script "sudo ifconfig en1 ether (x)"

activate

end tell


X changes every time


how can I change X with a dialog box?


Thanks

OS X Mavericks (10.9.2)

Posted on Mar 25, 2014 12:14 AM

Reply
Question marked as Best reply

Posted on Mar 25, 2014 2:24 AM

Try this:


display dialog "Please enter a value for x" default answer ""

set x to text returned of the result as string

set theShell to "sudo ifconfig en1 ether "


do shell script (theShell & x) with administrator privileges


----------------------------

If you actually want the results returned in Terminal rather the AppleScript editor, then try this instead:


display dialog "Please enter a value for x" default answer ""

set x to text returned of the result as string

settheShellto "sudo ifconfig en1 ether "


tell application "Terminal"


activate


do script (theShell & x)

end tell

2 replies
Question marked as Best reply

Mar 25, 2014 2:24 AM in response to Troubled Person

Try this:


display dialog "Please enter a value for x" default answer ""

set x to text returned of the result as string

set theShell to "sudo ifconfig en1 ether "


do shell script (theShell & x) with administrator privileges


----------------------------

If you actually want the results returned in Terminal rather the AppleScript editor, then try this instead:


display dialog "Please enter a value for x" default answer ""

set x to text returned of the result as string

settheShellto "sudo ifconfig en1 ether "


tell application "Terminal"


activate


do script (theShell & x)

end tell

Replace variable with answer in Applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.