OpenSourceEcon / BootCamp2019

Repository of syllabi, lecture notes, Jupyter notebooks, code, and problem sets for OSE Lab Boot Camp 2019
88 stars 97 forks source link

Sublime Text [or other editor] button in Mac Finder #15

Open rickecon opened 5 years ago

rickecon commented 5 years ago

@fediskhakov gave me a great Mac hack yesterday. This allows you to have a Sublime Text button in your Finder window on a Mac that you can either drag files to it to open them or click on it to open a blank file. image

  1. Open the Automator app on your Mac.
  2. Choose "Application" as the type of Automator document to create.
  3. Choose "Run AppleScript" from the Actions menu.
  4. Paste the following code script into the AppleScript window.
    on run
    set st2 to POSIX path of (path to application "Sublime Text")
    set subl to st2 & "Contents/SharedSupport/bin/subl"
    tell application "Finder"
        copy selection to theSelected
        set outputPathList to {}
        repeat with anItem in theSelected
            copy "'" & ((POSIX path of (anItem as alias)) as string) & "'" to end of outputPathList
        end repeat
        set AppleScript's text item delimiters to " "
        set currentPath to outputPathList as string
        set AppleScript's text item delimiters to ""
        if currentPath is equal to "" then
            set currentPath to "'" & (POSIX path of (target of front window as string)) & "'"
        end if
    end tell
    tell current application to do shell script "'" & subl & "' -n " & currentPath
    end run
  5. In the Automator menu, select File, then Save..., then name the application "SublimeFinderButton.app", save it to the /Applications/ folder, and choose the file format of "Application".
  6. Open a finder window, navigate to the /Applications/ folder, press command and click and drag the new SublimeFinderButton.app application to the Finder bar.
  7. Finally, change the icon to the Sublime Text icon by right clicking on the "Applications/Sublime Text.app" and selecting Get info option. Click on the Sublime Text icon in the upper left of the Get info window. A blue outline will appear around it. Press command-c to copy the icon to clipboard. Then right click on your new "Applications/SublimeFinderButton.app" application and click on the Get info option. Click on the Automator icon in the upper left of the Get info window. A blue outline will appear around it. Press command-v to paste the Sublime Text icon.

Enjoy

rebekahanne commented 5 years ago

Thank you!