Applescript Coding

Supporting 10.7 and up
Snakesitter

Applescript Coding

Postby Snakesitter » Thu May 07, 2009 11:27 am

I am trying to write a simple routine to get readings from two Phidget sensors. I need to use Applescript, and have Le Stang's excellent Script Addition installed.

One, would anyone have an example of a successful "sensor read" Applescript they would be willing to share -- of any sensor type? A working model would be a huge help.

Two, would anyone have any feedback on my own attempt? After speaking with a very kind Le Stang himself (and then breaking his penultimate line into two), mine now looks like this:

Code: Select all

set theConnection to IKConnect 29292
IKGetStatus theConnection
IKGetAnalogicInputsCount theConnection
IKGetVersion theConnection
set a to IKRawReadAnalogicInput 1 kit theConnection
set b to IKRawReadAnalogicInput 6 kit theConnection
IKDisconnect theConnection


However, when I try and run this, I get the following errors:

Line 1
Summary: The compiler objects to the number
script error: around characters 21 to 36
script error: A number can’t go after this identifier. (-2740)


Lines 2-4
Summary: The compiler objects to “theConnection”
script error: around characters 43 to 56 / 56 to 69 / 44 to 57
script error: Expected end of line, etc. but found identifier. (-2741)


Lines 5-6
Summary: The compiler objects to “kit”
script error: around characters 63 to 66
script error: Expected end of line, etc. but found identifier. (-2741)


Line 7
Summary: The compiler objects to “theConnection”
(otherwise as above)

Finally, a random thought: is the "ScriptingAdditions/" folder supposed to have the "/" on the end? Could that be causing the issue?

Thank you all,

Snakesitter

Re: Applescript Coding

Postby Snakesitter » Sun May 10, 2009 9:44 pm

Success! The "/" turned out to to be The Issue after all.

My script right now is as follows, presented in the hope it may help someone else in the future:

Code: Select all

try
set theConnection to IKConnect 29292
IKGetStatus theConnection
IKGetAnalogicInputsCount theConnection
IKGetVersion theConnection
set RawUL to IKRawReadAnalogicInput 1 kit theConnection
set RawUR to IKRawReadAnalogicInput 6 kit theConnection
set RawLL to IKRawReadAnalogicInput 1 kit theConnection
set RawLR to IKRawReadAnalogicInput 6 kit theConnection
IKDisconnect theConnection
end try


Thanks to both Le and Bob for scripting assistance.

I did, however, have a few additional questions on Phidgets-specific code.
1. Did anyone ever determine a way to make "IKGetStatus" testable?
2. Does "IKGetAnalogicInputsCount" return all inputs, used or not, or just the ones with sensors attached? In other words, can this be used as a test function, too?
3. What use does "IKGetVersion" serve in the script?

Thank you all,


Return to “macOS”

Who is online

Users browsing this forum: No registered users and 2 guests