Skip to content

Instantly share code, notes, and snippets.

@imkiva
Last active March 22, 2021 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imkiva/a460a57b03db591b1cda9d1fb259f1ed to your computer and use it in GitHub Desktop.
Save imkiva/a460a57b03db591b1cda9d1fb259f1ed to your computer and use it in GitHub Desktop.
Open emacs cli editing the file selected in Finder.app
on run {input, parameters}
tell application "Finder"
set flist to selection as alias list
if length of flist = 0 then
set fpath to ""
else
set fpath to quoted form of POSIX path of first item of flist
end if
end tell
set fullCommand to "exec emacs " & fpath
tell application "iTerm"
set term_window to (create window with default profile)
set sesh to (current session of term_window)
tell sesh to write text fullCommand
end tell
end run
@imkiva
Copy link
Author

imkiva commented Mar 22, 2021

Tested on macOS Big Sur 11.2

  • Create Quick Action in Automator.app
  • Click Library -> Utilities and double click Run AppleScript.
  • Workflow receives files or folders in Finder.app.
  • Paste the gist to editing area.
  • Save as Emacs.workshop to ~/Library/Services
  • Go to System Preference -> Keyboard -> Shortcut -> Services and give the Emacs under Files and Folders a shortcut.
  • To prevent two windows from opening when you use the keyboard Shortcut when iTerm2 is not already running, set iTerm2's Preferences -> General -> Startup to Only Restore Hotkey Window for the Window restoration policy. credit: here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment