Posted on 07-19-2012 08:43 AM
Hi everyone,
Running into a slight snag here collecting some information from an application as an extension attribute.
This is the script I am using to populate the EA:
#!/bin/sh
## Only run this script if the computer has CEDPro on it
if [ -e "/Applications/ColorEyes Display Pro/ColorEyes Display Pro.app" ]; then
## In order to pass variables from osascript you need to set a variable in bash = to the result of the osascript
Req=$(/usr/bin/osascript <<endCERequest
tell application "System Events"
key down command
key down shift
do shell script "open '/Applications/ColorEyes Display Pro/ColorEyes Display Pro.app'"
delay 10
key up command
key up shift
tell process "QuickLicenseRT"
delay 3
click pop up button 1 of window "License Options" -- access the menu to select show field data
key code 125 -- down arrow
key code 125 -- down arrow
keystroke return -- press return when we get to "Show Field Data"
delay 2
keystroke tab -- tab to access the text data (request number)
key code 125 -- down arrow twice to get to the request number
key code 125
delay 2
key down command
keystroke "c" -- copy it to the clip board
key up command
delay 2
keystroke return -- close the License Options window
delay 5
keystroke return -- if the user has a setting out of place in their sys prefs, CEDP will alert them to this. Close this window.
set RequestNumber to the clipboard -- throw the data into a variable
return RequestNumber
end tell
end tell
endCERequest
)
if [ $Req -eq $Req ]; then ## Check to make sure $Req returned a numeric value. -eq only evaluates numbers, so will fail if it's a non numeric
echo "<result>$Req</result>"
fi
killall ColorEyes Display Pro
else
echo "<result>NA</result>"
exit 0
fi
As you can see it's running an osascript since this crappy app requires gui scripting in order to get the info I need. The problem I'm running into is the EA never gets populated. If I run the script out of terminal or Casper Remote, it outputs correctly.
Anything obvious that my fuzzy brain has missed?
Posted on 07-19-2012 08:49 AM
i'm just going to take a stab and say that it has something to do with Casper running the script as a user that's different than the one that's logged in. Can you try logging in interactively to the system you try this on with your Casper management account and then see what happens?
Posted on 07-19-2012 09:14 AM
I agree with Jared.
The problem is GUI scripting. A GUI (non-command line) application must run under the Finder, which must run under a user's login.
For this script to work it requires a user to first be logged in to a machine and then the shell script must run under that user's credentials since it's calling AppleScript's GUI scripting.
I'm not familiar with the application that's getting scripted but if it's writing to .plist files then you can more easily manage those with shell scripts regardless of whether someone is logged in to a machine. Have you checked whether the information you need is in a .plist file?
Posted on 07-19-2012 10:03 AM
Sorry for the false alarm. It's me and my stupid brain. Forgot that the request number is pulled as a 3 item field, and my -eq check was failing on "too many arguments." The reason I have that is to ensure an integer is returned, since the request number is ALWAYS an integer (and if anything else is returned, the user probably interfered with the script). So I awked it down to the integer field and all is right with the world.
I have already warned our helpdesk that this is a gui script and what that means to the user, and am putting checks in place for unlocking desktops if needed and checking that a user is logged in at all.
@talkingmoose: I WISH the app was smart enough to write to plists, but this number is generated "on the fly"... Be thankful you're not familiar with this software, it's a nightmare.