1

This question already has an answer here:

i'd like to be able to open an app as a different user. For example PC1 is my main account and PC7 is my secondary one.

I can achieve the effect in terminal using

su - pc7 insert password /Applications/Application.app/Contents/MacOS/ApplicationName

How can i use the automator to make a script/app whatever that does this by a simple doubleclick?

Thanks

marked as duplicate by Graham Miln, nohillside Mar 31 '14 at 12:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

You can not trivially launch graphical applications as another user.

A Proxy Process is Required

To launch a graphical application as another user, that user must be logged in to a graphical session and have a process running within their session able to launch your desired application.

Prior to OS X 10.9, this could be approximated via the launchctl command. See How to launch a GUI application in another user's graphical session? for a detailed discussion.

0

You can simply save your example as a text file adding the suffix .command or .sh to it to execute it with a double-click. AppleScript can call an .sh-script, too, with

do shell script "/path/to/yourscript.sh"

Not sure if Automator can do the same.

But su basically only works with commands not using the Aqua GUI of Mac OS X. So if you try to open an application like for example TextEdit this way, it wont be able to open a window on the Desktop.

  • su works fine with GUI apps…? – grg Mar 31 '14 at 11:57
0

If you were were to open AppleScript, you would use the following format:

do shell script "/usr/bin/su - " & user & " -c " & "'" & cmd & "'" with administrator privileges password "blahblah"

If you wanted to make a shell script, you'd need to chmod a+x the file and write it out like this:

#!/usr/bin/env bash
su -c "/Applications/Application.app/Contents/MacOS/ApplicationName" -s /bin/sh pc7

Or, you can write it how I would write it:

#!/usr/bin/bash
su -c "/Applications/Application.app/Contents/MacOS/ApplicationName" -s /bin/sh pc7

  1. Save the file as YourScritpt.sh
  2. Add executable permissions by typing chmod a+x YourScript.sh in Terminal
  3. Right-click the file in Finder and select 'Open with" and select "Other"
  4. Select Terminal as the application to open the file (change to All Applications)
  5. You do not need to select "Always Open With"

Not the answer you're looking for? Browse other questions tagged .