Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

This is related to this question here, except that, in addition to removing the Finder, I want to do it automatically. There are several solutions on the web that suggest using this AppleScript:

tell application "System Events"
    tell UI element "Finder" of list 1 of process "Dock"
        perform action "AXShowMenu"
        click menu item "Remove from Dock" of menu 1
    end tell
end tell

Unfortunately, saving this as an application and having it run at login doesn't work; interestingly, running it within Script Editor does work, but this doesn't solve the problem of removing the Finder automatically.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The solution is to create a LaunchAgent (man launchctl for more info) that runs the above script via the command-line. Essentially, you want to store the script above in a file, say 'killfinder.scpt' and then run the command osascript /path/to/killfinder.scpt.

We want to do this automatically at login, so we use a LaunchAgent. Since I want to use this because I use Pathfinder and my wife doesn't, I'm going to put it in ~/Library/LaunchAgents, but if you want this to be system wide, put it in /Library/LaunchAgents.

You will have three files:

  1. A UNIX script
  2. An AppleScript (optional)
  3. A LaunchAgent XML plist

Script File

  1. Put this in an appropriate path. For example, I stored it in ~/dev/scripts/killfinder.bash.
  2. Create the file and add this content:

    #!/bin/bash
    osascript /path/to/AppleScriptFile.scpt
    
  3. Make sure the permissions are correct (i.e. chmod ug+x killfinder.bash)

AppleScript File

You can call osascript directly with AppleScript code as an argument. I leave that as an exercise to the reader; in that case, you can creating this file. But if you want to do it this way: 1. Put this in an appropriate path. 2. Create the file and add this content:

    tell application "System Events"
        tell UI element "Finder" of list 1 of process "Dock"
            perform action "AXShowMenu"
            click menu item "Remove from Dock" of menu 1
        end tell
    end tell
  1. Make sure the permissions are correct (i.e. chmod ugo+r Finder\ Remove.scpt)

LaunchAgent XML plist

  1. Put this in ~/Library/LaunchAgents or /Library/LaunchAgents depending if you just want this behavior for your personal account or system-wide.

  2. Create a file called com.<whateveryouwant>.KillFinder.plist with the following content:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
       <key>Label</key>
       <string>com.<whateveryouwant>.KillFinder</string>
       <key>Program</key>
       <string>/path/to/unixscript</string>
       <key>RunAtLoad</key>
       <true/>
    </dict>
    </plist>
    

    It's important to make sure the 'string' value after the Label key is correct as well as the path to the unix script.

Now all you have to do is exit and login and it should work!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.