Script will launch from terminal, and using the execute in terminal but not in execute shell script directly

ok so this must be trivial but im a newbee

so i have this command

emacsclient -n -e '(yequake-toggle "org-capture")'

if i launch it directly from iterm2 it works well. if i launch it via the execute in terminal macro it also works

but

when i try to launch it directly using the execute shell script macro (since i dont want to get any output)


i get an error:

2019-01-04 11:44:16 emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type "M-x server-start".
emacsclient: No socket or alternate editor.  Please use:

	--socket-name
	--server-file      (or environment variable EMACS_SERVER_FILE)
	--alternate-editor (or environment variable ALTERNATE_EDITOR)
 Macro “Trying” cancelled (while executing Execute Shell Script).

what am i missing here?

best

Z

The issue here is usually that the pristine and vanilla shell environment used by Execute Shell Script needs to explicitly acquire the variables which are available to the quite separate shell environment used by Terminal.app

thx @ComplexPoint.

but im afraid that your explanation a bit way over my head :slight_smile:

is there a solution for that ie define the variables so that KM is aware of the shell env?

thx!

Z

The first stop is probably this page, and in particularly the "How to set a path" section:

https://wiki.keyboardmaestro.com/action/Execute_a_Shell_Script

See also this recent thread:

Hey Z,

What are you trying to accomplish?

(I've never used the emacsclient command before.)

In any case – when running in a normal Execute a Shell Script action you're running in a black box that knows nothing whatsoever about your shell setup.

-Chris

thx @ccstone!!

well emacsclient tries to connect to an emacs daemon that is running. but launching it via KM dosent work. is there i can make the KM command aware that the emacs daemon is running?

best

Z

Hey Z,

Connect in what way?

What is the desired outcome?

-Chris

Check the difference between running the command:

env

in the Terminal where it works, and via an Execute Shell Script command. Probably there is some environment variable that is not configured within the Keyboard Maestro environment that is describing the emacs connection details.

thx alot @peternlewis

there is indeed a huge difference but alas im not sure im savy enough to understand how to relate this to my issue

here is the KM env command output

KMVAR_Text_Encoded=Keyboard Maestro Status Menu
KMVAR_Year=2021
KMVAR_TEST=-1926
KMVAR_Entry=21,3
KMVAR_Macros_Total=61
KMVAR_Day=30
KMVAR_Size=6320,2560
SHELL=/bin/zsh
KMVAR_PauseScreenshotNotify=false
KMVAR_Mouse=1381,472
KMVAR_Macro_Export_Path=/Users/zeltak/Desktop/Keyboard Maestro Macro Groups/Enabled Macros
KMVAR_Best_Date=0
TMPDIR=/var/folders/hv/6s4f153s4gbbtmmmzkzbb7br0000gn/T/
KMVAR_File=/Users/zeltak/ZH_tmp/MOP310209-2018-11-30.pdf
KMVAR_Check_Clipboard=206
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.mCbda4A5Ce/Render
KMVAR_Add_Year=3
KMVAR_Sceen_Shots=true
KMVAR_Added=1541773639
KMVAR_NowControl=666055.762602
USER=zeltak
KMVAR_HTML_Result_Button=Cancel
KMVAR_palorg_MacrosInfo={"macros":[{"macroUUID":"F2000715-579B-4EEF-8045-CAF2BAEAFA36","macroName":"01)emacs","prefixNumber":"01","macroNameNoPrefix":"emacs"},{"macroUUID":"CA63319C-9AAA-45D0-B592-5149FC46D72B","macroName":"02)chrome","prefixNumber":"02","macroNameNoPrefix":"chrome"},{"macroUUID":"BB4AA232-79F3-4D25-8CC0-BCCDF13B03A7","macroName":"03)ssh_karif","prefixNumber":"03","macroNameNoPrefix":"ssh_karif"},{"macroUUID":"1E05200D-E59E-4292-B1B6-EFB740E00795","macroName":"activity monitor","prefixNumber":"","macroNameNoPrefix":"activity monitor"},{"macroUUID":"9214C7FF-D35B-4C3F-BCF8-E5A000BA9126","macroName":"emacsclient","prefixNumber":"","macroNameNoPrefix":"emacsclient"},{"macroUUID":"F7847713-7B41-458B-90F3-DE4FD451C37B","macroName":"fantastical","prefixNumber":"","macroNameNoPrefix":"fantastical"},{"macroUUID":"0ACAA7E0-7CF0-410A-A016-FE847FF3496A","macroName":"Finder","prefixNumber":"","macroNameNoPrefix":"Finder"},{"macroUUID":"EB5A0295-A10B-4B8B-BCC8-650A38A6EB50","macroName":"Finder small ","prefixNumber":"","macroNameNoPrefix":"Finder small"},{"macroUUID":"BC301F05-6597-46E8-891D-D1DB1447854D","macroName":"ftools","prefixNumber":"","macroNameNoPrefix":"ftools"},{"macroUUID":"A12D19BC-4FC7-4422-9D62-AB48E8D6D881","macroName":"gmail","prefixNumber":"","macroNameNoPrefix":"gmail"},{"macroUUID":"4ED6E98E-5E9F-40B9-B52C-AE6EEF0DCB22","macroName":"iterm_bash","prefixNumber":"","macroNameNoPrefix":"iterm_bash"},{"macroUUID":"F296DEC6-9BDA-4B07-9790-DA9CBBA24BD7","macroName":"keepass-search","prefixNumber":"","macroNameNoPrefix":"keepass-search"},{"macroUUID":"9DC042E9-D901-4D07-B575-84442431904D","macroName":"Keyboard Maestro","prefixNumber":"","macroNameNoPrefix":"Keyboard Maestro"},{"macroUUID":"7C58BAC2-3266-44DB-BDCF-376720E6F7B5","macroName":"Macro by Name","prefixNumber":"","macroNameNoPrefix":"Macro by Name"},{"macroUUID":"ECF25481-E079-401D-A99F-85F8D89CD501","macroName":"mc","prefixNumber":"","macroNameNoPrefix":"mc"},{"macroUUID":"4C12C209-EDD1-4BA6-9980-9A7EB8554FEE","macroName":"MC search","prefixNumber":"","macroNameNoPrefix":"MC search"},{"macroUUID":"BA6BE576-5643-45E1-9E83-83E775485F09","macroName":"mission control ","prefixNumber":"","macroNameNoPrefix":"mission control"},{"macroUUID":"DBB2BB0E-2AE3-45BD-A381-C34729F2BCE6","macroName":"qBittorrent","prefixNumber":"","macroNameNoPrefix":"qBittorrent"},{"macroUUID":"6BF6FC15-88FC-4310-B7DF-5E074AA01823","macroName":"QMC","prefixNumber":"","macroNameNoPrefix":"QMC"},{"macroUUID":"49A5BB7D-FEBE-43F4-B77A-0EE493862D31","macroName":"smartlist play ","prefixNumber":"","macroNameNoPrefix":"smartlist play"},{"macroUUID":"A474C41B-D148-4A1F-B7EE-CB3E3F2A51E3","macroName":"vnc","prefixNumber":"","macroNameNoPrefix":"vnc"},{"macroUUID":"6AF33BFA-4DF0-49FA-ABE2-A64D601DCDF9","macroName":"whatsapp","prefixNumber":"","macroNameNoPrefix":"whatsapp"}],"groupUUID":"49B95023-1287-4CE4-926E-13EC24F2F160","groupName":"Z1 Launcher","groupToggleMacroUID":"9A8F5636-ABC5-43C6-A3CF-9C7732B4001A"}
COMMAND_MODE=unix2003
KMVAR_palorg_GroupName=Z1 Launcher
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.cLtz9FLJhP/Listeners
KMVAR_One_Entry=Test | Entry
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
KMVAR_Path=/Users/zeltak/ZH_tmp/counts/
KMVAR_palorg_NewMacroName=03)ssh_karif
KMVAR_DND__palorg_lastDividerChar=⎯
KMVAR_sign_off=Thanks again
KMVAR_ωFolderMenu=<option value="/Users/zeltak/Documents/bitbar">bitbar</option>
<option value="/Users/zeltak/Documents/JRiver">JRiver</option>
<option value="/Users/zeltak/Documents/PhraseExpress">PhraseExpress</option>
<option value="/Users/zeltak/Documents/ScanSnapHome.localized">ScanSnapHome.localized</option>
<option value="/Users/zeltak/Documents/Zoom">Zoom</option>
KMVAR_Skip_Smart_Folders=1
KMVAR_safari_page_source=/var/folders/hv/6s4f153s4gbbtmmmzkzbb7br0000gn/T/Keyboard-Maestro-Script-B8818340-864E-4A76-873A-87435AC19AAD:128:209: execution error: Google Chrome got an error: Executing JavaScript through AppleScript is turned off. To turn it on, from the menu bar, go to View > Developer > Allow JavaScript from Apple Events. For more information: https://support.google.com/chrome/?p=applescript (12)
KMVAR_Add_Day=0
PATH=/usr/bin:/bin:/usr/sbin:/sbin
_=/usr/bin/env
KMVAR_Global_Configuration=1
KMVAR_Alarm=2
PWD=/
KMVAR_Trigger=test11
KMVAR_palorg_GroupToggleMacroUID=9A8F5636-ABC5-43C6-A3CF-9C7732B4001A
KMVAR_selectedFile=/Users/zeltak/ThemeDB/Workshop/tile.icons/OLDsvg/win.info.svg
KMVAR_Result_Button=Open Log File
KMVAR_Screen_Coord=0, 0, 3440, 1440
KMVAR_Screen_Data=SCREEN DATA
Scrn#	Left, Top, Width, Height
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.	-1440, 236, 1440, 900
2.	0, 0, 3440, 1440
KMVAR_Best_Path=/Users/zeltak/Documents/PhraseExpress
KMVAR_WinFrame=998,29,925,1378
XPC_FLAGS=0x0
KMVAR_Multiple_Entries=Good|Better|Best
KMVAR_Month=11
KMVAR_BestWidth=6320
KMVAR_Groups_Total=17
KMVAR_Best_Added=1543204332
XPC_SERVICE_NAME=0
KMVAR_palorg_GroupUUID=49B95023-1287-4CE4-926E-13EC24F2F160
HOME=/Users/zeltak
KMVAR_KMVarPrefix=MSW__
KMVAR_MWO__ScreenNum=1
KMVAR_iScrn=2
SHLVL=2
KMVAR_ωRoot=/Users/zeltak/Documents
KMVAR_List=Hello,There,How,Are,You
KMVAR_Name=counts
KMVAR_Alert_Button=Stop
KMVAR_Text=Keyboard Maestro Status Menu
KMVAR_Add_Month=0
KMVAR_selectedPath=/Users/zeltak/mreview/Amplifierw/2017 Record/
KMVAR_DND_MSW__WindowList=APP_NAME,WINDOW_NAME,TOP,LEFT,WIDTH,HEIGHT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
qutebrowser,JRiver Panel - qutebrowser,0,23,851,731
iTerm2,ssh.karif: /usr/local/bin/mosh karif (mosh-client),2578,23,857,1417

LOGNAME=zeltak
KMINSTANCE=174606D6-A1A4-4F8A-B02E-2167FBD1A42E:018F9FBC-DD5C-45A6-9F2E-CBCAD9DB0EF3
KMVAR_Base_Name=MOP310209-2018-11-30
KMVAR_Index=5
KMVAR_palorg_ActualMacroName=05)ssh_karif
KMVAR_ωPath=/Users/zeltak/Documents/Zoom
KMVAR_MoveActionResult=OK
KMVAR_NumOfScreens=2
KMVAR_BestIndex=2
DISPLAY=/private/tmp/com.apple.launchd.sP0kKhHbqI/org.macosforge.xquartz:0
KMVAR_safari_page_headings_list_html=<ul class="headings-list">
</ul>
SECURITYSESSIONID=186a8
SQLITE_EXEMPT_PATH_FROM_VNODE_GUARDS=/Users/zeltak/Library/WebKit/Databases
KMVAR_Trigger_Encoded=test11
KMVAR_Extension=pdf
KMVAR_LastControl=666055.762602
KMVAR_ωFolderList=/Users/zeltak/Documents/bitbar:::/Users/zeltak/Documents/JRiver:::/Users/zeltak/Documents/PhraseExpress:::/Users/zeltak/Documents/ScanSnapHome.localized:::/Users/zeltak/Documents/Zoom
KMVAR_safari_page_url=https://mail.google.com/mail/u/0/?tab=cm&zx=1a9kkuzmcil0m&shva=1#inbox

vs the terminal output

zeltak@imbp-50:~|⇒  env
TERM_SESSION_ID=w1t1p0:DCE8903E-2B3C-49B3-A9A4-259FB15C9C17
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.cLtz9FLJhP/Listeners
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.mCbda4A5Ce/Render
COLORFGBG=11;15
ITERM_PROFILE=zterm
XPC_FLAGS=0x0
PWD=/Users/zeltak
SHELL=/bin/zsh
SECURITYSESSIONID=186a8
LC_CTYPE=UTF-8
TERM_PROGRAM_VERSION=3.2.6
TERM_PROGRAM=iTerm.app
PATH=/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
DISPLAY=/private/tmp/com.apple.launchd.sP0kKhHbqI/org.macosforge.xquartz:0
COLORTERM=truecolor
TERM=xterm-256color
HOME=/Users/zeltak
TMPDIR=/var/folders/hv/6s4f153s4gbbtmmmzkzbb7br0000gn/T/
USER=zeltak
XPC_SERVICE_NAME=0
LOGNAME=zeltak
__CF_USER_TEXT_ENCODING=0x0:0:0
ITERM_SESSION_ID=w1t1p0:DCE8903E-2B3C-49B3-A9A4-259FB15C9C17
SHLVL=1
OLDPWD=/Users/zeltak
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
PAGER=less
LESS=-R
LSCOLORS=Gxfxcxdxbxegedabagacad
EDITOR=/usr/bin/emacsclient -nc
_=/usr/bin/env

would appreciate any help and tips anyone has

best

Z

The difference is likely the PATH, and hence the version of emacsclient you are running.

See this comment from StackOverflow:

A possible cause is that you are using the Mac OS X stock emacsclient (version 22) that can't find Emacs 24. Check that your $PATH doesn't look like this: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin: because for homebrew symlinks to work, /usr/local/bin must come before /usr/bin

Your PATH in Keyboard Maestro is:

Your PATH in Terminal is:

Try running the command:

which emacsclient

In both Terminal and Keyboard Maestro.

You may just be able to use the full path of emacsclient in the Keyboard Maestro action, or alternatively configure the Keyboard Maestro PATH (ENV_PATH variable) as described in the link @ComplexPoint posted earlier:

thx so much @peternlewis!!

this was indeed the cause! after evaluating which emacsclient in both i see that indeed its calling cleint from /usr/local/bin/emacsclient. once i adjusted this in the code in KM it now works :smiley:

thx all again

Z

1 Like