Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added argument support #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions emacs-client-mac.scpt
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
tell application "Terminal"
try
-- we look for <= 2 because Emacs --daemon seems to always have an entry in visibile-frame-list even if there isn't
set frameVisible to do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -e '(<= 2 (length (visible-frame-list)))'"
if frameVisible is not "t" then
-- there is a not a visible frame, launch one
do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c -n"
end if
on error
-- daemon is not running, start the daemon and open a frame
do shell script "/Applications/Emacs.app/Contents/MacOS/Emacs --daemon"
do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c -n"
end try
end tell
on run
runclient("")
end run

-- bring the visible frame to the front
tell application "Emacs" to activate
on open argv
set filename to quoted form of POSIX path of item 1 of argv
runclient(filename)
end open

on runclient(filename)
tell application "System Events" to set isRunning to (name of processes) contains "Terminal"

tell application "Terminal"
try
set frameVisible to do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -e '(<= 2 (length (visible-frame-list)))'"
if frameVisible is not "t" then
-- there is a not a visible frame, launch one
do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c -n " & filename
else if filename is not "" then
-- there is a viible frame, just open a file in exiting one
do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n " & filename
end if
on error
-- daemon is not running, start the daemon and open a frame
do shell script "/Applications/Emacs.app/Contents/MacOS/Emacs --daemon"
do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c -n " & filename
end try
end tell

-- bring the visible frame to the front
tell application "Emacs" to activate

-- close terminal
if not isRunning then
tell application "Terminal" to quit
end if
end runclient