Skip to main content
Question

Script running in Self Service to Prompt user for input


DBrowning
Forum|alt.badge.img+24

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.

11 replies

Forum|alt.badge.img+17
  • Contributor
  • 881 replies
  • July 21, 2015

Yes, I use CocoaDialog to prompt for user input. How are you prompting for it? A read-type command?


Forum|alt.badge.img+17
  • Valued Contributor
  • 231 replies
  • July 21, 2015

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"'


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • July 21, 2015

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.


DBrowning
Forum|alt.badge.img+24
  • Author
  • Esteemed Contributor
  • 668 replies
  • July 21, 2015

I am using shell script


DBrowning
Forum|alt.badge.img+24
  • Author
  • Esteemed Contributor
  • 668 replies
  • July 21, 2015

@alexjdale yes I am using a read command.

!/bin/sh

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


stevewood
Forum|alt.badge.img+35
  • Employee
  • 1797 replies
  • July 21, 2015

Like @alexjdale, I use CocoaDialog for this as well.


Forum|alt.badge.img+17
  • Valued Contributor
  • 231 replies
  • July 21, 2015

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.


Forum|alt.badge.img+17
  • Valued Contributor
  • 231 replies
  • July 21, 2015

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.


Forum|alt.badge.img+16
  • Valued Contributor
  • 1002 replies
  • July 21, 2015

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)

bentoms
Forum|alt.badge.img+35
  • Legendary Contributor
  • 4331 replies
  • July 22, 2015

You can also upload an AppleScript.

No need for faffing around with bash to AppleScript to bash..

Instead faff around with AppleScript to bash.


Forum|alt.badge.img+31
  • Honored Contributor
  • 2721 replies
  • July 22, 2015

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:


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings