Posted on 07-21-2015 08:05 AM
Anyone been able to do such a thing?
Have a script that when run outside of Self Service it works fine and prompts for input. When running via SS, it doesn't prompt the user.
Posted on 07-21-2015 08:09 AM
Yes, I use CocoaDialog to prompt for user input. How are you prompting for it? A read-type command?
Posted on 07-21-2015 08:16 AM
Note that if you're using AppleScript, 10.9 and up have tightened security in a way that makes osascript trickier to use. You'll want to code something like launchctl bsexec console_pid osascript -e 'tell app "Self Service" to display dialog "Interact with me"'
Posted on 07-21-2015 08:20 AM
Yeah, the likely issue is that you're using AppleScript, which is designed and expected to be run by the user. When a script gets run from Self Service, its run as root, and the OS will throw an error since you're (unknowingly) asking the root user to display a dialog to the logged in user.
Posted on 07-21-2015 08:44 AM
I am using shell script
Posted on 07-21-2015 08:45 AM
@alexjdale yes I am using a read command.
echo "Is this a Laptop (l) or Desktop (w)?:"
read type
echo "What is the location of this machine? (BUR, DAL, NHP, etc):"
read location
OS=Mac
sn=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
newsn=$(echo "${sn:4}")
name=$type$location$OS$newsn
Posted on 07-21-2015 08:55 AM
Like @alexjdale, I use CocoaDialog for this as well.
Posted on 07-21-2015 01:26 PM
Shell scripts don't have really have concept of a GUI. The read builtin expects to work within a terminal session. Opening a terminal window would be possible, but ugly and it would carry security risks. CocoaDialog, Pashua, or AppleScript are your best bets for this sort of interaction.
Posted on 07-21-2015 01:41 PM
Brief AppleScript in bash example:
#!/bin/bash
/bin/launchctl bsexec $(who -u | sed -n s/'.*.console.*[ ]'//p) /usr/bin/osascript -e 'tell app "Self Service" to display dialog "Enter a location (BUR, DAL, NHP, etc) and then click the type of this computer." buttons {"Laptop","Desktop"} default answer "etc"'
You could use the AppleScript choose from list function to ensure valid locations.
Posted on 07-21-2015 02:37 PM
Similar to @joshuasee Here is what I used to ask for a printer location.
LOCATION=$(/usr/bin/osascript<<END
tell application "System Events"
activate
set the answer to text returned of (display dialog "Enter a FLOOR or ROOM or PRINTER.
ie: AA1 or AA123 or AA123-P455
Only general use printers may be added." default answer "" buttons {"Continue"})
end tell
END)
Posted on 07-21-2015 11:46 PM
You can also upload an AppleScript.
No need for faffing around with bash to AppleScript to bash..
Instead faff around with AppleScript to bash.
Posted on 07-22-2015 01:28 PM
Here is and example of what I have used for returning elements in a bash script from Apple script
getSite() {
theSite=$(osascript <<AppleScript
set mySites to {"Minneapolis", "Cupertino", "New York", "Hong Kong", "Amsterdam", "Eau Claire"}
set selectedSite to {choose from list mySites}
AppleScript
echo "${theSite}"
)
}
getSite
echo "${theSite}"
This is what it looks like: