Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mjaco

macrumors newbie
Original poster
Dec 15, 2009
3
0
Can anyone help me with these two Applescripts (Very Simple One! lol)

I want to be able to make a applescript which will determine what OS is running on the machine and choose which Applescript to run.

I want machine running Leopard to run the Leopard Airport Card script and the same in Snow but with the SL airport card script. I don't know how to do so hopefully someone will be able to help?

These are the two AS's:

Leopard Turn OFF Airport Card
Code:
do shell script "/usr/sbin/networksetup -setairportpower off"
SL Turn Off Airport Card
Code:
--list all of the network hardware ports
set the_ports to (do shell script "/usr/sbin/networksetup -listallhardwareports")
set old_delims to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to return
set the_count to the count of text items in the_ports
on error
set AppleScript's text item delimiters to old_delims
end try

--get the port number of the AirPort device
repeat with x from 1 to the_count
if text item x of the_ports contains "AirPort" then
set device_line to (text item (x + 1) of the_ports)
end if
end repeat
set AppleScript's text item delimiters to ":"
try
set the_port to (text item 2 of device_line)
set AppleScript's text item delimiters to old_delims
on error
set AppleScript's text item delimiters to old_delims
end try

--do shell script "/usr/sbin/networksetup -setairportpower" & the_port & " off" with administrator privileges
Hope this makes sense.

Many Thanks,
Matt
 
Last edited by a moderator:
Code:
tell application "Finder" -- check whether Lion, or Snow Leopard is running
   set v to version as string
end tell
set versnum to (characters 1 thru 4 of v as text) as number
 
What ??

tell application "Finder" -- check whether Lion, or Snow Leopard is running
set v to version as string
end tell
set versnum to (characters 1 thru 4 of v as text) as number

I'm completely new to this and haven't clue how to tell finder how to check what OS is running and then tell it to run which app?

Sorry for being a pain.
 
That's AppleScript code.
Just paste it into your AppleScript Editor, and run it

The "Tell Finder" ... "end tell" is called a tell block.
It basically asks the Finder to give us the information we want, its version.
Open the Finder's Dictionary (AppleScript Editor->File Menu->Open Dictionary) to see what you can ask the Finder to do for you.

Here's a little fancier version of the script, that'll make the output number (10.7 for Lion, 10.6 for SL etc...) easier to notice:

Code:
tell application "Finder" -- check whether Lion, or Snow Leopard is running
	set v to version as string
end tell
set versnum to (characters 1 thru 4 of v as text) as number
say versnum
display dialog versnum buttons {"OK"}
return versnum
 
What ??

tell application "Finder" -- check whether Lion, or Snow Leopard is running
set v to version as string
end tell
set versnum to (characters 1 thru 4 of v as text) as number

I'm completely new to this and haven't clue how to tell finder how to check what OS is running and then tell it to run which app?

Sorry for being a pain.

LOL. That provides how English-like AppleScript is! :p
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.