-- -- New_Radio_ManagerAppDelegate.applescript -- New_Radio_Manager -- -- Created by Roger Rehr on 8/5/11. -- Copyright 2011-2013 Roger Rehr. All rights reserved. -- Last updated January 26, 2013 script New_Radio_ManagerAppDelegate property parent : class "NSObject" property AutoLog : missing value property LFoot : missing value property RFoot : missing value property Mic : missing value property CWKey : missing value property LFootSelect : missing value property RFootSelect : missing value property MicSelect : missing value property KeySelect : missing value global Lfootstr global RFootstr global Micstr global Keystr global AutoLogstr global LFootAutostr global RFootAutostr global MicAutostr global KeyAutostr on QuitButton_(sender) quit end QuitButton_ on SendComm_(sender) Sendit() end SendComm_ on ReadID_(sender) ReadDisk() end ReadID_ on AutoLogOn_(sender) set AutoLogstr to "On" say "on" end AutoLogOn_ on AutoLogOff_(sender) set AutoLogstr to "Off" say "off" end AutoLogOff_ on LFootMan_(sender) set LFootAutostr to "Man" SetIndices() Sendit() say "man" end LFootMan_ on LFootAuto_(sender) set LFootAutostr to "Auto" SetIndices() Sendit() say "auto" end LFootAuto_ on RFootMan_(sender) set RFootAutostr to "Man" SetIndices() Sendit() say "man" end RFootMan_ on RFootAuto_(sender) set RFootAutostr to "Auto" SetIndices() Sendit() say "auto" end RFootAuto_ on MicMan_(sender) set MicAutostr to "Man" SetIndices() Sendit() say "man" end MicMan_ on MicAuto_(sender) set MicAutostr to "Auto" SetIndices() Sendit() say "auto" end MicAuto_ on KeyMan_(sender) set KeyAutostr to "Man" SetIndices() Sendit() say "man" end KeyMan_ on KeyAuto_(sender) set KeyAutostr to "Auto" SetIndices() Sendit() say "auto" end KeyAuto_ on LFoot50_(sender) set Lfootstr to "50" SetIndices() Sendit() say "50" end LFoot50_ on LFoot144_(sender) set Lfootstr to "144" SetIndices() Sendit() say "1 44" end LFoot144_ on LFoot222_(sender) set Lfootstr to "222" SetIndices() Sendit() say "2 22" end LFoot222_ on LFoot432_(sender) set Lfootstr to "432" SetIndices() Sendit() say "4 32" end LFoot432_ on LFoot903_(sender) set Lfootstr to "903" SetIndices() Sendit() say "9 oh 3" end LFoot903_ on LFoot1296_(sender) set Lfootstr to "1296" SetIndices() Sendit() say "twelve ninety six" end LFoot1296_ on LFootGHz_(sender) set Lfootstr to "GHz" SetIndices() Sendit() say "Giga" end LFootGHz_ on RFoot50_(sender) set RFootstr to "50" SetIndices() Sendit() say "50" end RFoot50_ on RFoot144_(sender) set RFootstr to "144" SetIndices() Sendit() say "1 44" end RFoot144_ on RFoot222_(sender) set RFootstr to "222" SetIndices() Sendit() say "2 22" end RFoot222_ on RFoot432_(sender) set RFootstr to "432" SetIndices() Sendit() say "4 32" end RFoot432_ on RFoot903_(sender) set RFootstr to "903" SetIndices() Sendit() say "9 oh 3" end RFoot903_ on RFoot1296_(sender) set RFootstr to "1296" SetIndices() Sendit() say "twelve ninety six" end RFoot1296_ on RFootGHz_(sender) set RFootstr to "GHz" SetIndices() Sendit() say "Giga" end RFootGHz_ on Mic50_(sender) set Micstr to "50" SetIndices() Sendit() say "50" end Mic50_ on Mic144_(sender) set Micstr to "144" SetIndices() Sendit() say "1 44" end Mic144_ on Mic222_(sender) set Micstr to "222" SetIndices() Sendit() say "2 22" end Mic222_ on Mic432_(sender) set Micstr to "432" SetIndices() Sendit() say "4 32" end Mic432_ on Mic903_(sender) set Micstr to "903" SetIndices() Sendit() say "9 oh 3" end Mic903_ on Mic1296_(sender) set Micstr to "1296" SetIndices() Sendit() say "twelve ninety six" end Mic1296_ on MicGHz_(sender) set Micstr to "GHz" SetIndices() Sendit() say "Giga" end MicGHz_ on Key50_(sender) set Keystr to "50" SetIndices() Sendit() say "50" end Key50_ on Key144_(sender) set Keystr to "144" SetIndices() Sendit() say "1 44" end Key144_ on Key222_(sender) set Keystr to "222" SetIndices() Sendit() say "2 22" end Key222_ on Key432_(sender) set Keystr to "432" SetIndices() Sendit() say "4 32" end Key432_ on Key903_(sender) set Keystr to "903" SetIndices() Sendit() say "9 oh 3" end Key903_ on Key1296_(sender) set Keystr to "1296" SetIndices() Sendit() say "twelve ninety six" end Key1296_ on KeyGHz_(sender) set Keystr to "GHz" SetIndices() Sendit() say "Giga" end KeyGHz_ on SetGUI_(sender) SetGUI() end SetGUI_ -- on SetGUI() -- global flex50id -- global k3_144id -- global szc2duo1_222id -- global szc2duo2_432id -- global szc2duo3_903id -- global szc2duo4_1296id -- global szc2duo5_ghzid -- global Keystr -- tell application "System Events" -- if Keystr is equal to "50" then -- say flex50id -- set the frontmost of application processes whose id is flex50id as integer to true -- else if Keystr is equal to "144" then -- say k3_144id -- set the frontmost of application processes whose id is k3_144id as integer to true -- else if Keystr is equal to "222" then -- say szc2duo1_222id -- set the frontmost of application processes whose id is szc2duo1_222id as integer to true -- else if Keystr is equal to "432" then -- say szc2duo2_432id -- set the frontmost of application processes whose id is szc2duo2_432id as integer to true -- else if Keystr is equal to "903" then -- say szc2duo3_903id -- set the frontmost of application processes whose id is szc2duo3_903id as integer to true -- else if Keystr is equal to "1296" then -- say szc2duo4_1296id -- set the frontmost of application processes whose id is szc2duo4_1296id as integer to true -- else if Keystr is equal to "GHz" then -- say szc2duo5_ghzid -- set the frontmost of application processes whose id is szc2duo5_ghzid as integer to true -- end if -- end tell -- end SetGUI on ReadDisk() -- say "Read Disk" global flex50id global k3_144id global szc2duo1_222id global szc2duo2_432id -- global szc2duo3_903id global szc2duo4_1296id global szc2duo5_ghzid set f to "Macintosh HD:flex50.txt" as alias try set ref_num to open for access f on error close access f try set ref_num to open for access f on error errText number errNum display dialog "couldn't open file because" & return & return & return & errNum & " - " & errText end try end try read f as text set flex50id to result close access ref_num set f to "Macintosh HD:k3_144.txt" as alias try set ref_num to open for access f on error close access f try set ref_num to open for access f on error errText number errNum display dialog "couldn't open file because" & return & return & return & errNum & " - " & errText end try end try read f as text set k3_144id to result close access ref_num set f to "Macintosh HD:szc2duo1_222.txt" as alias try set ref_num to open for access f on error close access f try set ref_num to open for access f on error errText number errNum display dialog "couldn't open file because" & return & return & return & errNum & " - " & errText end try end try read f as text set szc2duo1_222id to result close access ref_num set f to "Macintosh HD:szc2duo2_432.txt" as alias try set ref_num to open for access f on error close access f try set ref_num to open for access f on error errText number errNum display dialog "couldn't open file because" & return & return & return & errNum & " - " & errText end try end try read f as text set szc2duo2_432id to result close access ref_num -- set f to "Macintosh HD:szc2duo3_903.txt" as alias -- try -- set ref_num to open for access f -- on error -- close access f -- try -- set ref_num to open for access f -- on error errText number errNum -- display dialog "couldn't open file because" & return & return & return & errNum & " - " & errText -- end try -- end try -- read f as text -- set szc2duo3_903id to result -- close access ref_num set f to "Macintosh HD:szc2duo4_1296.txt" as alias try set ref_num to open for access f on error close access f try set ref_num to open for access f on error errText number errNum display dialog "couldn't open file because" & return & return & return & errNum & " - " & errText end try end try read f as text set szc2duo4_1296id to result close access ref_num set f to "Macintosh HD:szc2duo5_ghz.txt" as alias try set ref_num to open for access f on error close access f try set ref_num to open for access f on error errText number errNum display dialog "couldn't open file because" & return & return & return & errNum & " - " & errText end try end try read f as text set szc2duo5_ghzid to result close access ref_num -- say "Done with read disk" end ReadDisk on Sendit() -- say "Send It" global catradios global portRef tell window 1 set Lfootstr to LFoot's selectedCells()'s valueForKey_("title") as strings -- say "El footstr is" -- say Lfootstr if Lfootstr is equal to "50" then set Lfoo to 49 else if Lfootstr is equal to "144" then set Lfoo to 50 else if Lfootstr is equal to "222" then set Lfoo to 51 else if Lfootstr is equal to "432" then set Lfoo to 52 else if Lfootstr is equal to "903" then set Lfoo to 53 else if Lfootstr is equal to "1296" then set Lfoo to 54 else if Lfootstr is equal to "GHz" then set Lfoo to 55 end if end tell tell window 1 set RFootstr to RFoot's selectedCells()'s valueForKey_("title") as strings -- say "our footstr is " -- say RFootstr if RFootstr is equal to "50" then set RFoo to 49 else if RFootstr is equal to "144" then set RFoo to 50 else if RFootstr is equal to "222" then set RFoo to 51 else if RFootstr is equal to "432" then set RFoo to 52 else if RFootstr is equal to "903" then set RFoo to 53 else if RFootstr is equal to "1296" then set RFoo to 54 else if RFootstr is equal to "GHz" then set RFoo to 55 end if end tell tell window 1 set Micstr to Mic's selectedCells()'s valueForKey_("title") as strings -- say Micstr if Micstr is equal to "50" then set MicFoo to 49 else if Micstr is equal to "144" then set MicFoo to 50 else if Micstr is equal to "222" then set MicFoo to 51 else if Micstr is equal to "432" then set MicFoo to 52 else if Micstr is equal to "903" then set MicFoo to 53 else if Micstr is equal to "1296" then set MicFoo to 54 else if Micstr is equal to "GHz" then set MicFoo to 55 end if end tell tell window 1 set Keystr to CWKey's selectedCells()'s valueForKey_("title") as strings -- say Keystr if Keystr is equal to "50" then set KeyFoo to 49 else if Keystr is equal to "144" then set KeyFoo to 50 else if Keystr is equal to "222" then set KeyFoo to 51 else if Keystr is equal to "432" then set KeyFoo to 52 else if Keystr is equal to "903" then set KeyFoo to 53 else if Keystr is equal to "1296" then set KeyFoo to 54 else if Keystr is equal to "GHz" then set KeyFoo to 55 end if end tell set CP290cmd to 49 as text set CP290cmd to MakeString({49, 13}) serialport write CP290cmd to portRef delay 0.02 set CP290cmd to MakeString({Lfoo, 13}) serialport write CP290cmd to portRef delay 0.02 set CP290cmd to MakeString({RFoo, 13}) serialport write CP290cmd to portRef delay 0.02 set CP290cmd to MakeString({MicFoo, 13}) serialport write CP290cmd to portRef delay 0.02 set CP290cmd to MakeString({KeyFoo, 13}) serialport write CP290cmd to portRef delay 0.02 -- do shell script "~/Documents/arduino-serial -b 57600 -p /dev/tty.usbserial-A10022Nw -n" & 9 -- do shell script "~/Documents/arduino-serial -b 57600 -p /dev/tty.usbserial-A10022Nw -s" & "," -- do shell script "~/Documents/arduino-serial -b 57600 -p /dev/tty.usbserial-A10022Nw -n" & Lfoo -- do shell script "~/Documents/arduino-serial -b 57600 -p /dev/tty.usbserial-A10022Nw -n" & RFoo -- do shell script "~/Documents/arduino-serial -b 57600 -p /dev/tty.usbserial-A10022Nw -n" & MicFoo -- do shell script "~/Documents/arduino-serial -b 57600 -p /dev/tty.usbserial-A10022Nw -n" & KeyFoo -- say "Done with Send it" end Sendit on MakeString(theBytes) set thestr to "" repeat with i from 1 to length of theBytes set thestr to thestr & (ASCII character (item i of theBytes)) end repeat return thestr end MakeString on FocusFinder() -- say "Focus Finder" global procid global procidold global flex50id global k3_144id global szc2duo1_222id global szc2duo2_432id -- global szc2duo3_903id global szc2duo4_1296id global szc2duo5_ghzid global Lfootstr global RFootstr global Micstr global Keystr global AutoLogstr global focusradio global focusindex tell application "Finder" set procidold to procid get (id of every process whose frontmost is 1) set procid to result end tell if procid - procidold is not equal to 0 then if procid - flex50id = 0 then set focusradio to 50 set focusindex to 0 if AutoLogstr is equal to "On" then do shell script "~/Documents/TCPStuff/EchoServer/tcpclient 50000" end if SetIndices() Sendit() say "6" else if procid - k3_144id = 0 then set focusradio to 144 set focusindex to 1 if AutoLogstr is equal to "On" then do shell script "~/Documents/TCPStuff/EchoServer/tcpclient 144000" end if SetIndices() Sendit() say "2" else if procid - szc2duo1_222id = 0 then set focusradio to 222 set focusindex to 2 if AutoLogstr is equal to "On" then do shell script "~/Documents/TCPStuff/EchoServer/tcpclient 222000" end if SetIndices() Sendit() say "two 22" else if procid - szc2duo2_432id = 0 then set focusradio to 432 set focusindex to 3 if AutoLogstr is equal to "On" then do shell script "~/Documents/TCPStuff/EchoServer/tcpclient 432000" end if SetIndices() Sendit() say "four 32" -- else if procid - szc2duo3_903id = 0 then -- set focusradio to 903 -- set focusindex to 5 -- -- if AutoLogstr is equal to "On" then -- do shell script "~/Documents/TCPStuff/EchoServer/tcpclient 903000" -- end if -- SetIndices() -- Sendit() -- say "9 oh 3" else if procid - szc2duo4_1296id = 0 then set focusradio to 1296 set focusindex to 5 if AutoLogstr is equal to "On" then do shell script "~/Documents/TCPStuff/EchoServer/tcpclient 1296000" end if SetIndices() Sendit() say "12 96" else if procid - szc2duo5_ghzid = 0 then set focusradio to 2304 set focusindex to 6 if AutoLogstr is equal to "On" then do shell script "~/Documents/TCPStuff/EchoServer/tcpclient 1400000" end if SetIndices() Sendit() say "giga" else say "no SDR" end if end if -- say "Done with Focus Finder" end FocusFinder on SetIndices() -- say "Set indices" global Lfootstr global RFootstr global Micstr global Keystr global focusradio global focusindex global portRef if LFootAutostr is equal to "Auto" then set Lfootstr to focusradio tell window 1 LFoot's selectCellAtRow_column_(focusindex,0) -- set enabled of every cell to false end tell end if if RFootAutostr is equal to "Auto" then set RFootstr to focusradio tell window 1 RFoot's selectCellAtRow_column_(focusindex,0) end tell -- set enabled of every cell to false end if if MicAutostr is equal to "Auto" then set Micstr to focusradio tell window 1 Mic's selectCellAtRow_column_(focusindex,0) end tell -- set enabled of every cell to false end if if KeyAutostr is equal to "Auto" then set Keystr to focusradio tell window 1 CWKey's selectCellAtRow_column_(focusindex,0) end tell -- set enabled of every cell to false end if -- say "Done with Set Indices" end SetIndices on applicationWillFinishLaunching_(aNotification) -- Insert code here to initialize your application before any files are opened global Lfootstr global RFootstr global Micstr global Keystr global AutoLogstr global LFootAutostr global RFootAutostr global MicAutostr global KeyAutostr global procid global procidold global flex50id global k3_144id global szc2duo1_222id global szc2duo2_432id -- global szc2duo3_903id global szc2duo4_1296id global szc2duo5_ghzid global focusindex global focusradio global portRef set procid to 0 set procidold to 0 set focusradio to 50 set focusindex to 1 set AutoLogstr to "Off" set LFootAutostr to "Man" set RFootAutostr to "Man" set MicAutostr to "Man" set KeyAutostr to "Man" set portRef to serialport open "/dev/cu.usbserial-A3000IeB" bps rate 19200 data bits 8 parity 0 stop bits 1 handshake 0 if portRef is equal to -1 then display dialog " could not open RadioManager USB port " end if do shell script "open -a \"" & "/Users/73w3sz/Documents/NewVersions/W3SZServer_4_1/build/Debug/EchoServer.app alias" & "\"" ReadDisk() FocusFinder() Sendit() fauxIdle() -- say "Load completed" end applicationWillFinishLaunching_ on fauxIdle() global bandval FocusFinder() performSelector_withObject_afterDelay_("fauxIdle", missing value, 0.1) -- say "idle" end fauxIdle on applicationShouldTerminate_(sender) -- Insert code here to do any housekeeping before your application quits global portRef serialport close portRef return true return current application's NSTerminateNow end applicationShouldTerminate_ end script