Run a sudo command on system startup via Applescript?

Hey, I'm trying to hide the Spotlight icon on my menu bar using the sudo command shown here:
http://osxdaily.com/2011/12/12/hide-spotlight-menu-icon-mac-os-x-lion/
It works fine, but when I reboot my Mac (I tend to turn it off at night since it has a habit of waking from sleep by itself) the icon has re-appeared, and I need to run the command again.
I'd ideally like to write an Applescript to run on launch to execute the two commands (which also requires entering my password), but I've not been successful, I get various errors talking about authentication and such.
Is there an easier way to get this icon permanently hidden? I use Alfred, so while I make use of the Spotlight index, I never touch the magnifying glass icon, and I like to keep a clean menu bar!

You don't need applescript. What you need to create is a LaunchAgent. Lingon (available through the App Store) can help you write it. But, there are other sources that can show you how to write the raw file and put it in the LaunchAgents folder, like here: http://www.devdaily.com/mac-os-x/launchd-examples-launchd-plist-file-examples-ma c

Similar Messages

  • Put a command in system startup

    Hi
    I want to put the following command in system startup:
    echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
    How can it that?
    Regards

    https://wiki.archlinux.org/index.php/Sy … rary_files

  • How does one run a shell script at system startup?

    Hi,
    I am trying to unmount my Boot Camp hard drive on my MacBook Pro. Now what I could do is create an automator action, save it as an application and then put it into my user´s login items. I am wondering though - shouldnt it be possible to run a simple shell script command like +diskutil unmount /Volumes/"Boot Camp"+ sometime during the startup process?
    Or to put it another way - is there an easy way to do this or do i have to create an manage a daemon through launchd ?
    Your help is very much appreciated.

    sorry I forgot to mention that there is a bug in Lingon which creates a plist incorrectly if you enter your script explicitly on line 2. At least I haven't been able to make it work. A workaround I always use it the following.
    Save your script as a *plain text* file from your favorite text editor. change the extension to .sh and make the file unix executable. Now, when you ccreate a launch daemon using Lingon, enter the path to that file instead of the script itself.
    This always works for me.
    Good luck!

  • DHCP request at system startup via shell script

    Hi all,
    I administer about 120 macs and a couple of weeks ago the network admin changed the ipv4 network and the dhcp-leases, -ranges.
    My macs do not get an ip address when they start up.
    It takes about one minute until the request is succeeded.
    I am about to write a shell script that starts a dhcp request over the network.
    I want to use the same command that the network system pref (Renew DHCP Lease) uses.
    I read the bootpd, xinetd, lookupd manual but I am not sure wich one is the correct deamon to use.
    Someone can help?
    Thanks in advance
    Cheers Thorsten

    Seen the ipconfig yet?
    http://developer.apple.com/documentation/Darwin/Reference/ManPages/man8/ipconfig .8.html
    Two ways to renew a lease in Terminal, adjust your enNUMBER accordingly...
    sudo ipconfig set en0 BOOTP;sudo ipconfig set en0 DHCP
    sudo ifconfig en1 down;sudo ifconfig en1 up

  • Applescript for running sudo commands in terminal

    I'm a newbie when it comes to Applescript and was wondering if someone could help with a basic request. I need to write a small script to do the following:
    1. Launch terminal
    2. Run the 'Sudo -s' command
    3. Enter the administrator password (in plain text)
    and then
    4. run some sudo commands like "sudo defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array-add administrator"
    I actually WANT the administrator password to be in the script in plain text even though I understand the security risks (I will literally be the only person to ever see the script). I've trawled forums all over but can't seem to find what I am looking for and cannot get it working by patching together the various commands I have found. Thanks in advance for any help you can give!
    Sean

    I've included two examples.  The preferred way & the hacker way.
    with administrator
    It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
        Author: rccharles
        For testing, run in the Script Editor.
          1) Click on the Event Log tab to see the output from the log statement
          2) Click on Run
        For running shell commands see:
        http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
    on run
        -- Write a message into the event log.
        log "  --- Starting on " & ((current date) as string) & " --- "
        --  debug lines
        set unixDesktopPath to POSIX path of "/System/Library/User Template/"
        log "unixDesktopPath = " & unixDesktopPath
        set quotedUnixDesktopPath to quoted form of unixDesktopPath
        log "quoted form is " & quotedUnixDesktopPath
        try
            set fromUnix to do shell script "sudo ls -l  " & quotedUnixDesktopPath with administrator privileges
            display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix
        on error errMsg
            log "ls -l error..." & errMsg
        end try
    end run
    This version has an inline password.
    Notice the echo 'password' |
    The single quotes are no accident.
    It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
        Author: rccharles
        For testing, run in the Script Editor.
          1) Click on the Event Log tab to see the output from the log statement
          2) Click on Run
        For running shell commands see:
        http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
    on run
        -- Write a message into the event log.
        log "  --- Starting on " & ((current date) as string) & " --- "
        --  debug lines
        set unixDesktopPath to POSIX path of "/System/Library/User Template/"
        log "unixDesktopPath = " & unixDesktopPath
        set quotedUnixDesktopPath to quoted form of unixDesktopPath
        log "quoted form is " & quotedUnixDesktopPath
        try
            set fromUnix to do shell script "echo 'password' | sudo ls -l  " & quotedUnixDesktopPath
            display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix
        on error errMsg
            log "ls -l error..." & errMsg
        end try
    end run

  • Sudo Command in Bash Script

    So I created a simple bash script to run on login.....
    one of the commands is the following:
    sudo "something something something"....
    One thing I haven't learned in my years of Unix is how do you get a bash script to run a sudo command without having to enter a password?  I know this is trival, but just a quick 'this is how you do it' would be cool.
    Thanks ahead of time on this really dumb question.

    There's a few ways to do this.  Here's two (pick the method you like):
    Method 1: Using "askpass".
    With this you always do sudo -A command.  The -A argument tells sudo to execute a command that echos the password to stdout.  That command is something you write.  For this explaination let's call the command pw and stick it /usr/local/bin.  So it's full pathname would be /usr/local/bin/pw.
    sudo -A can get the pathname to pw a number of ways.
    1. From the sudoers file.
    Use visudo to add the following line to the sudoers file:
    Defaults:ALL    askpass=/usr/local/bin/pw
    2. Using the SUDO_ASKPASS environment variable.
    export SUDO_ASKPASS=/usr/local/bin/pw
    This might work too (assuming SUDO_ASKPASS has been previously exported):
    SUDO_ASKPASS=/usr/local/bin/pw sudo -A command
    Method 2: Have sudo read the password from stdin
    echo -n password | sudo -S command
    The -S option tells sudo to read the password from stdin so echo pipes it in (without the ending newline).
    The only relatively secure scheme of these two methods is the askpass (-A) method.  At least with that method you have a chance of encrypting/hiding your password down in the command that echoes it to stdout.  The -S method would contain your password explicitly in a script somewhere unless you make other provisions to encrypt/hide it with that technique.

  • Run the "nice" command on startup?

    Hi all,
    Since I've experienced overheating problems, I've dug a little and discovered this wonderful "nice" command, that's currently letting me install Windows 7 on a VM thanks to VirtualBox without turning my logic board into a critter. My question is, is there a way (and a good reason) to run this command right after booting up, say via AppleScript? I haven't noticed any sluggish behavior when running this command, but right now, VirtualBox is running, and my temp censor displays readings oscillating between 60°C and 70°C, far below the 120°C I've noted yesterday, right before my MBP shut down from exhaustion...
    So, how-to...?
    Message was edited by: Didier Caizergues

    Get more memory. My system started paging like crazy when running Virtual PC.
    The point of this topic was, how do I automatize this running "nice" in Terminal. I already added Terminal to my Startup Items, but it merely opens at the prompt, and I have to manually enter "nice", then return, to enter "nice mode". Haven't thought of typing "renice" since I started using this function...
    You can invoke terminal ( unix ) commands from an applescript program. I am not familiar with nice, but the following applescript file did start up Windows. I could not figure out whether or not the nice command did anything.
    The first thing that you need to do is to make the text into an AppleScript program.
    Start the AppleScript Editor
    /Applications/AppleScript/Script Editor.app
    In Snow Leopard it's at: /Applications/Utilities/AppleScript Editor
    Copy the script text to the Applescript editor.
    Save the text to a file as an application and do not check any of the boxes below.
    !http://farm4.static.flickr.com/3544/3390737677_645a847e28.jpg?v=0!
    If you want access to the script from your Script Menu, move the script (the saved script application file) to your
    ~/Library/Scripts folder. You can also drag it to your Dock or make an alias for it on the Desktop.
    -- Write a message into the event log.
    -- To see this output, run from script editor after clicking on Event Log tab.
    log "  --- Starting on " & ((current date) as string) & " --- "
    set my text item delimiters to ", "
    try
       set theFile to escapeString("/Users/mac/Documents/virtual pc version-7.0/Windows XP Professional.vpc7")
       log theFile
       set see to "nice -n 5 open " & theFile
       log "see= " & see
       set results to do shell script see
    on error
       display dialog "error results for " & see
    end try
    on escapeString(thisString)
       set thisString to alterString(thisString, "\\", "\\\\")
       set thisString to alterString(thisString, " ", "\\ ")
       set thisString to alterString(thisString, quote, "\\" & quote)
    end escapeString
    on alterString(thisText, delim, replacement)
       set resultList to {}
       set {tid, my text item delimiters} to {my text item delimiters, delim}
       try
          set resultList to every text item of thisText
          set text item delimiters to replacement
          set resultString to resultList as string
          set my text item delimiters to tid
       on error
          set my text item delimiters to tid
       end try
       return resultString
    end alterString

  • Unable to run a Batch File Operating System Command

    Using XI 3.0, I am unable to run a Batch File Operating System Command After Message Processing.
    My Batch file:
    gpg -se -r BOA3RSKY --armor --passphrase-fd 0 %1 < C:\Progra~1\GNU\GnuPG\gpgin
    My Command Line (ID scenario)
    exec "cmd.exe /c C:\Progra~1\GNU\GnuPG\boagpg.bat %F"
    If I execute
    exec "cmd.exe /c type C:\Progra~1\GNU\GnuPG\boagpg.bat >xis.txt"
    It displays the contents of boagpg.bat file in xis.txt.
    I just don't understand why when I run the batch file, I would expect an %F.asc encrypted file in the same directory as the %F unencrypted file.
    Any ideas?
    or will I need Basis to create commands that will allow me to run GPG from XI Command Line?

    Check this links if its helpful
    http://help.sap.com/saphelp_nw04/helpdata/en/bb/c7423347dc488097ab705f7185c88f/frameset.htm
    /people/sap.user72/blog/2004/01/30/command-line-help-utility
    Check this thread a similar problem
    Process Integration (PI) & SOA Middleware
    Note 841704 - XI File & JDBC Adapter: Operating system command
    http://service.sap.com/sap/support/notes/841704
    Try to see the below links
    /people/michal.krawczyk2/blog/2005/08/17/xi-operation-system-command--error-catching
    OS Command on FTP
    OS command line script - Need help
    FTP - Run OS Command before file processing
    Note: reward points if solution found helpfull
    Regards
    Chandrakanth.k

  • Problem running sudo command in script

    Hello,
    I try to run this script.
    #!/bin/bash
    sudo /bin/cat /dev/input/event1 >> /home/tom/.log/log.bin &
    The sudoers entry
    %users ALL= NOPASSWD: /bin/cat /dev/input/event1 >> /home/tom/.log/log.bin
    I get the following error!
    $ Passwort: sudo: pam_authenticate: Kommunikationsfehler
    Kommunikationsfehler = eng: communication error
    What's wrong with that?
    Thank you!
    clementis

    Sorry, for being not precise.
    I created the alias in .bashrc in my $home directory. In sudoers all users are allowed to key in this command without a passwort entry.
    I know how to autostart in xfce and so created an autostart entry but unfortunatly it doesn't work for my "special" command.
    What I did:
    1. I wrote a script (first post) and tried to autostart it in xfce. For that command I created an entry in sudoers in order to avoid enter root passwort. The script didn't start.
    Then...
    2. I created an autostart entry (deleted the first one - see point 1) and entered the whole command (cat .../event1 >> $home...) in the xfce autostart input window. The idea was to run the command directly and not through a script. But it didn't work.
    Therefore I tried to run alter the command to "bash cat .../event1 >> $home ...." Didn't work either.
    3. I also deleted the autostart entry no 2. and created the alias in .bashrc in my home directory. Now created a new autostart entry trying to start the alias. Didn't work.
    I also tried to set the Terminal option in the file $home/.config/autostart/log.desktop to "true".
    So it looked like this:
    [Desktop Entry]
    Encoding=UTF-8
    Version=0.9.4
    Type=Application
    Name=log
    Comment=event1
    Exec= sudo cat /dev/input/event1 >> /home/tom/.cblog/log.bin &
    StartupNotify=false
    Terminal=true
    Hidden=false
    The alias for example works well if I enter it in xterm.
    So, I don't know why it isn't working! :-(
    Thank you for any help
    Clementis

  • To run command on system...

    Hi geeks...
    How I can to do to execute a command on system?
    I use Linux... so... how I can to do to run df command by Java?
    Thanks.

    hi there
    i dono about UNIX but i have a code that works fine on WIN
    i think u can modify that according to yr need so here is the code
    String os_name = System.getProperty("os.name");
    os_name = os_name.toUpperCase();
    String[] command ;
    if(os_name.indexOf("XP") != -1){
    command = new String[] {"cmd", "/C", "start", "\"\"", File_Name};
    else if(os_name.indexOf("NT") != -1){
    command =new String[] {"cmd", "/C", "start", "\"\"", File_Name};
    else if(os_name.indexOf("2000") != -1){
    command = new String[] {"cmd", "/C", "start", "\"\"", File_Name};
    else {
    command = new String[] {"start", "\"\"", File_Name};
    try
    Process process = Runtime.getRuntime().exec(command);
    catch(IOException ioe)
    {/ yr error msg here}
    Here File_Name is the file which u want to run i mean it can be any file (Doc,HTML.......... and so on )
    hope this helps u
    Regards
    Satinderjit

  • Need Command Prompt, system reboots at startup

    Laptop will not boot to XP pro windows.  loops at reboot.    I do not have CD's for the system.  I used another XP service pack 2 install CD but when accessing the repair console the install CD cannot find any hard drives.   I used the Recovery console for the thinkpad and ran  all diagnostic tests and everything past.   I cannot find where I can access a command prompt so I can run the CHKDSK on the system to repair the corrupted boot file.  I sooner not use the restore the system until I see if the chkdsk works since the system has service pack 3 and other updates which are not restored and this may not fix the boot problem.
    How can I get to a command prompt?

    Here is more info About ACHI http://en.wikipedia.org/wiki/Advanced_Host_Control​ler_Interface
    Select compatibilty then boot windows cd to access command promp. If you have achi mode windows cannot see any disks

  • How to run commands upon system boot as user?

    How can I as a user run commands upon system boot? In Vixie's cron, one can use the @reboot syntax in a crontab, and the job is ran every time the cron daemon starts. Arch however, uses Dillon's cron which seems not support this feature.

    bwalk wrote:Hmm, does not work, because root owns init, so everything requires root. stb's version is valid, the -s parameter drops privileges to <USER>, spawns a shell and executes <COMMAND>. So, no security problem whatsoever.
    So there is nothing like @reboot in vixiecron?

  • Can't run bash or sudo commands

    I have a Mac Pro with OS X 10.8.2 and also an older iMac running OS X 10.6.8. On neither Mac can I run any bash or sudo commands! I always get command not found.
    Both Macs have fresh installs of OS X, did I forget to install something? Is X11 needed? or Xcode?
    Thanks for any help.

    Back up all data.
    Select
    Shell ▹ New Command
    from the Terminal menu bar. Copy and paste the following line into the text box that opens:
    mkdir disabled_shell_files; mv .profile .bash* $_
    Your old shell initialization and history files will be saved in a directory with the indicated name at the top level of your home directory.

  • Can flash player app be run and controlled in a system with only command line?

    I want to test my.  flash app in a remote linux pc. I am not permitted to install  desktop environment in that remote pc.
    So I am wondering if I can use flashplayer_10_sa_debug to run my app in a system with only command line access.
    And further, can I use some command option to interact with my app for doing something?
    If not , how can I reach my goal? Can you give me some advices?

    Hi,
    Can we get a status update for this? This seems to have broken Mac Projector files when published from a PC. Our old CD-ROM presentations no longer work. They throw the same error.
    Is there a bug ticket that we can follow? Any sort of timeline? I need to give an answer to my client on when this will be fixed. Telling them to disable Gatekeeper isn't really a great solution.

  • Assessing Command 'Analyze Source Files' via Command Line when running TestSTand Deployment Utility

    Our Software Configuration Manager is running the TestStand Command Line Deployment Build Tool (Ref: https://decibel.ni.com/content/docs/DOC-38947).
            When he builds the application,  the code will not be at the same location it was in development. 
    If you are Manually running the TestStand Deployment Utility, This is not a problem because everything is relative in the workspace.   Simply go to the Distributed Files Tab (of TestSTand Deployment Utility) and hit the, "Analyze Source Files" button.  This finds the required files and apparently creates an updated hard path to be used during the build (probably in the *.tsd).
    PROBLEM:  We auto-run the Command Line Deployment Build Tool (Command Line), and we do not have access to the, 'Analyze Source Files' command.
                As a result, our build consist of many warnings and the output is missing many files (the location of the files have not been updated).
    If we could access the 'Analyze Source Files' Command via command line, that would fix the issue. 
    FYI:  We use an automatic builder called Quick Build as our builder.
    Attachments:
    TestSTand Deployment Utility-Distributed Files Tab.PNG ‏76 KB

    Unfortunately it looks like Analyze Source Files does not have a command equivalent for the command line based on this article and attached PDF:
    https://decibel.ni.com/content/docs/DOC-38947
    That may be a good post for the TestStand Idea Exchange for consideration in future versions of TestStand.
    Michael K.

Maybe you are looking for