tag:blogger.com,1999:blog-12079827.post115968282874650102..comments2023-11-21T03:17:27.406-07:00Comments on Aric's Tech Blog: Running shell commands with Automator or AppleScript and executing with sudo privilegesArichttp://www.blogger.com/profile/06349808589965033115noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-12079827.post-16241940132582120012014-03-12T17:24:51.878-07:002014-03-12T17:24:51.878-07:00This comment has been removed by the author.Unknownhttps://www.blogger.com/profile/01867301480775607206noreply@blogger.comtag:blogger.com,1999:blog-12079827.post-66061665912228983902014-03-12T17:22:39.128-07:002014-03-12T17:22:39.128-07:00To start, I'm an audio engineer and not a prog...To start, I'm an audio engineer and not a programmer, so go easy on me.<br /><br />When I'm using my audio application, spotlight runs down the system indexing every minute or so. I have a script that "unloads" the mds launch deamon and reload it when I'm done with my editing.<br /><br />The scripts are these:<br /><br />sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist<br /><br />sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist<br /><br />Because it's a sudo command, it requires a password and the reason for your post is to run these shell scripts using Automator to increase workflow.<br /><br />I understand the purpose of your post, but not sure how to implement MY specific commands into your source code. Would you be so kind as to show me how to make that happen? I would greatly appreciate that!<br /><br />I like your idea of making the script universal instead of isolated to one user. (I'm trying to make it easy for other engineer friends of mine to just click an automator app in the dock to turn spotlight off and on without having to deal with all the rigmarole.)Unknownhttps://www.blogger.com/profile/01867301480775607206noreply@blogger.comtag:blogger.com,1999:blog-12079827.post-83029638534972600062012-07-16T08:36:40.470-07:002012-07-16T08:36:40.470-07:00John C. Welch had the closest answer. These singl...John C. Welch had the closest answer. These single line work as intended, prompting me for my currently logged in user's password:<br /><br />do shell script "foo" with administrator privileges<br /><br />If you need tho know the username then you can, of course, also use his short way as:<br /><br />set theUser to short user name of (system info)<br /><br />Great discussion! Thanks.Vicentehttps://www.blogger.com/profile/00536516080396137312noreply@blogger.comtag:blogger.com,1999:blog-12079827.post-46964205402931949792012-02-29T14:24:36.118-07:002012-02-29T14:24:36.118-07:00@running - This can be solved by chmod'ng the ...@running - This can be solved by chmod'ng the script file as only execute for the intended user(s), and chown'ng it a super user / groupMegabytehttps://www.blogger.com/profile/00423910376983450540noreply@blogger.comtag:blogger.com,1999:blog-12079827.post-35224783825520916892012-02-29T14:24:25.850-07:002012-02-29T14:24:25.850-07:00@running - This can be solved by chmod'ng the ...@running - This can be solved by chmod'ng the script file as only execute for the intended user(s), and chown'ng it a super user / groupMegabytehttps://www.blogger.com/profile/00423910376983450540noreply@blogger.comtag:blogger.com,1999:blog-12079827.post-66642074196742439132010-05-02T16:37:48.013-07:002010-05-02T16:37:48.013-07:00@John C. Welch. Well you got some of it right. Y...@John C. Welch. Well you got some of it right. Your tip about not needing System Events is correct so we can eliminate that. And I like getting the username from system info instead of running the shell script whoami. But I found the main command:<br />do shell script "foo" administrator privileges true user name theUser<br />Doesn't prompt me for my password and simply gives an error "Authorization failed." number -50Arichttps://www.blogger.com/profile/06349808589965033115noreply@blogger.comtag:blogger.com,1999:blog-12079827.post-37982876709389489482009-10-05T10:13:07.584-07:002009-10-05T10:13:07.584-07:00You're really overcomplicating parts of this. ...You're really overcomplicating parts of this. For example, you don't need System Events for "do shell script", that command is in Standard Additions.<br /><br />If you look at do shell script, you don't need the dialog stuff either. Just: <br /><br />do shell script "foo" administrator privileges true<br /><br />that will prompt the user for a user ID and password, and uses the 'real' system auth dialogs to do so.<br /><br />If you really want to get the user name of the currently logged in user, you don't need do shell script for that either. Again, from standard additions:<br /><br />set theUser to short user name of (system info)<br /><br />So using those lines:<br /><br />set theUser to short user name of (system info)<br /><br />do shell script "foo" administrator privileges true user name theUserJohn C. Welchhttps://www.blogger.com/profile/10293533581874023414noreply@blogger.comtag:blogger.com,1999:blog-12079827.post-37482369227884989932009-09-20T09:56:20.865-07:002009-09-20T09:56:20.865-07:00Brilliant - thank you!Brilliant - thank you!Alex Angashttps://www.blogger.com/profile/03904547908927379431noreply@blogger.comtag:blogger.com,1999:blog-12079827.post-37269082760579259552009-08-26T10:58:40.295-07:002009-08-26T10:58:40.295-07:00This was a very useful post. Thank you!This was a very useful post. Thank you!Anonymoushttps://www.blogger.com/profile/11947427724318320269noreply@blogger.comtag:blogger.com,1999:blog-12079827.post-41275971157631486222009-04-26T20:59:00.000-07:002009-04-26T20:59:00.000-07:00Hey running, I'm assuming you can't read.
The ent...Hey running, I'm assuming you can't read.<br /><br />The entire point of this article was to show you how to do it so you don't have to save your password as plain text. But apparently, you can't read three sentences into the article. <br /><br />QUOTE:<br />running said...<br />Please, tell me you are joking. You really mean it, seriously, you just put your password as a PLAINTEXT into your applescript. Just talk about security!<br /><br />Of course there is other way - just write <br />do shell script "rofllol" with administrator privileges<br /><br />yeah, it asks for a password, but HELL, you don't just save your password like that! aaarghArichttps://www.blogger.com/profile/06349808589965033115noreply@blogger.comtag:blogger.com,1999:blog-12079827.post-38903211790818064222009-04-25T19:59:00.000-07:002009-04-25T19:59:00.000-07:00Please, tell me you are joking. You really mean it...Please, tell me you are joking. You really mean it, seriously, you just put your password as a PLAINTEXT into your applescript. Just talk about security!<br /><br />Of course there is other way - just write <br />do shell script "rofllol" with administrator privileges<br /><br />yeah, it asks for a password, but HELL, you don't just save your password like that! aaarghautorhttps://www.blogger.com/profile/06066795701833771760noreply@blogger.comtag:blogger.com,1999:blog-12079827.post-61792331144149936192008-05-30T20:51:00.000-07:002008-05-30T20:51:00.000-07:00Thanks a lot for this, I was looking for a way to ...Thanks a lot for this, I was looking for a way to turn airport off from the keyboard. I've modified and updated it slightly as well:<BR/><BR/>on run {input, parameters}<BR/> tell application "System Events" to activate<BR/> tell application "System Events"<BR/> set the_password to "password"<BR/> display dialog "Admin password goes here." default answer "password" buttons {"OK", "Cancel"} default button "OK" with icon 2 with title "Password" with hidden answer<BR/> set the_password to text returned of the result<BR/> end tell<BR/> do shell script "sudo ifconfig en1 down" password the_password with administrator privileges<BR/>end runUnknownhttps://www.blogger.com/profile/10236712475633008303noreply@blogger.comtag:blogger.com,1999:blog-12079827.post-77438650182088914772007-12-09T16:32:00.000-07:002007-12-09T16:32:00.000-07:00Thanks for this, now my sister can run a sudo shel...Thanks for this, now my sister can run a sudo shell script.... You solved a rather messy problem for me.Jimhttps://www.blogger.com/profile/18344788134893554213noreply@blogger.comtag:blogger.com,1999:blog-12079827.post-55627452632979865862007-02-17T23:28:00.000-07:002007-02-17T23:28:00.000-07:00Wow, thanks heaps for this. i've now got a nice li...Wow, thanks heaps for this. i've now got a nice little app that asks for a password, checks to see if the processor performance is reduced or not, then reduces or not, and makes the display sleep either 1 or 60 mins.<BR/><BR/>I'll link you when i have it up somewhere :)<BR/><BR/>Al.Axman6https://www.blogger.com/profile/06210752966177293933noreply@blogger.comtag:blogger.com,1999:blog-12079827.post-1161572700152287972006-10-22T20:05:00.000-07:002006-10-22T20:05:00.000-07:00cambro543 wrote: Additional info on this post woul...<I> cambro543 wrote: <BR/>Additional info on this post would be very useful!</I><BR/><B><BR/>No problem.<BR/></B><BR/><I>First, you forgot the ';' after if [ $? -eq 1 ]</I><BR/><B><BR/>Huh? Works fine. Maybe I'm missing what you mean. Where do you want the ';'?<BR/></B><BR/><I>Second, the link given to download an example Automator script (click here) is not a link.</I><BR/><B><BR/>You're right. The link was broken and is now fixed, so you can download an Automator script with all the code that works great!<BR/></B><BR/><I>Finally, I can't get it to work once I add the ';' and substitute:<BR/><BR/>echo "you are a sudoer";<BR/><BR/>with my script (chmod 666 /path/to/file).</I><BR/><B><BR/>Again, not sure where you are putting the ';'<BR/><BR/>Download the script now that the link is fixed and check it out. If you have more questions, or can explain the ';' question better, post another comment and I'll follow up.</B>Arichttps://www.blogger.com/profile/06349808589965033115noreply@blogger.com