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

On invoking the shortcut, I receive an error popup reporting 'The action “Run Shell Script” encountered an error.' #56

Open
Reefersleep opened this issue May 20, 2018 · 19 comments

Comments

@Reefersleep
Copy link

Reefersleep commented May 20, 2018

On invoking the shortcut, I receive an error popup reporting 'The action “Run Shell Script” encountered an error.'

The popup has the options "OK" (dismissing the poup) and "Show Workflow", which opens "/Users/ree/Library/Services/", showing Emacs Anywhere.workflow. If I try to open it and run it in Automator, I get an error popup showing

The action “Run Shell Script” encountered an error.

161:177: execution error: System Events got an error: osascript is not allowed assistive access. (-25211)
52:64: execution error: System Events got an error: osascript is not allowed assistive access. (-1719)
emacsclient: could not get terminal name
emacsclient: error executing alternate editor """"

With only an "OK" button.

After some googling, I found that the osascript error had been experienced by people in other contexts. In particular, I reviewed this stack overflow issue: https://apple.stackexchange.com/questions/291574/osascript-is-not-allowed-assistive-access-1728

Following that, I tried giving the Emacs Anywhere.workflow file a checkmark in Security & Privacy > Allow the apps below to control your computer. It didn't make any difference.

@Reefersleep
Copy link
Author

Apparently, there were a few popups hiding behind all of my other windows, prompting me to allow Firefox and Automator to control my computer. I did so, and now, the error message I get is somewhat reduced:

emacsclient: could not get terminal name
emacsclient: error executing alternate editor """"

@zachcurry
Copy link
Owner

zachcurry commented May 20, 2018

Hi @Reefersleep 👋

I'm loving the username! I'm thinking my username should have been Reefercode 😄

I believe the answers you're looking for are in the README, albeit a garbled mess:

  • Be sure your Emacs server is running. Run this command in the terminal to fire it up 🔥 :
    emacs --daemon

  • If Emacs still doesn't launch when you invoke the shortcut, you either have errors in your init files, or more likely still, emacsclient is not being found in $PATH. The easy solution to this is to simply tell Emacs Anywhere where it is and how you want to run it like this.

  • You don't add permissions for Emacs Anywhere, rather the application you are using it with, namely Firefox for the example you've given. I'll reword this to avoid confusion in the README. And to be clear, permissions are not mandatory for Emacs Anywhere to launch Emacs.

I hope this helps! If not, let me know.

@Reefersleep
Copy link
Author

Hello 👋

Thanks! Sorry for being a bit curt when writing the issue. I had postponed it and wanted to get it out of the way, so it ended up very matter-of-factly :)

I normally use emacs --daemon and emacsclient without hitches. I tried with export EA_EDITOR='emacsclient -a "" -c', and it didn't seem to make a difference.

I tried giving Accessibility permissions to Firefox, but it made no difference.

@zachcurry
Copy link
Owner

zachcurry commented Jun 4, 2018

Does the following command create a new Emacs frame in your environment?
emacsclient -a "" -c

@Reefersleep
Copy link
Author

It does :) Both with the daemon running and not.

@zachcurry
Copy link
Owner

Excellent! I think if you add the absolute path to the EA_EDITOR export, it will work. On Mac I have to rebuild the PATH variable because osascript doesn’t run shell commands interactively. It’s possible the executable is not being found and simply prefixing the path to the command in your export will solve the problem.

Be sure you’ve got the latest version of Emacs Anywhere, a fully qualified path in your exported var, and be sure to put the export in your .bash_profile.

@Reefersleep
Copy link
Author

I tried putting export EA_EDITOR='/usr/local/bin/emacsclient -a "" -c' in my ~/.bash_profile, source ~/.bash_profile, and triggering the shortcut in Firefox - same error as before. Firefox has Accessability permissions.

@Reefersleep
Copy link
Author

Reefersleep commented Jul 1, 2018

It dawned on me that sourceing the file is not enough to the exported path in a global context, so I logged out and in and checked once again. This time I got the same error popup plus a popup saying that System Events.app needed permissions in Security & Privacy > Accessibility > Allow the apps below to control your computer.. I gave it permissions, which removed the new popup, but the same old error persists.

@zachcurry
Copy link
Owner

I'm not sure how to proceed...

My emacsclient file is in the same directory as yours and when I get the emacsclient: error executing alternate editor """" message I fix it by running emacs --daemon.

Questions

Does Emacs Anywhere work with any other applications in your environment?

Have you tried tinkering with the source code?

Solve a similar problem

Perhaps you could write a tiny, separate workflow that just invokes emacsclient to open a new fame. If you can get it to work, it will shed some light on this issue.

@Reefersleep
Copy link
Author

Reefersleep commented Jul 23, 2018

I decided to try Emacs Anywhere on a whim. It's not that important to me to get it working, so I'm going to let the issue rest for now. If it works for everyone else, great :)

Cheers for trying to help out! 👍

@d1egoaz
Copy link

d1egoaz commented Apr 22, 2020

I'm little late to the party, @Reefersleep you can checkout #67 as might be having a different osascript error

@Reefersleep
Copy link
Author

I tried doing as in #67, @d1egoaz , but it didn't make a difference in my case; I still get the same error.

@mrcnski
Copy link

mrcnski commented Sep 17, 2020

I was seeing the same error and had tried everything suggested here. I was running the server from my main Emacs instance so I eventually tried:

export EA_EDITOR='/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -a "" -c'

I had to also restart the server but now it works!

So make sure you are using an emacsclient that corresponds to your emacs.

The only remaining problem is that my main Emacs instance gets the focus instead of the new frame that comes up. This seems to be a separate issue with multiple displays.

@LucaMarconato
Copy link

I am experiencing the same problem.

I have tried @m-cat approach but it didn't work.
Specifically, my emacsclient is invoking /usr/local/bin/emacsclient, so I have replaced EA_EDITOR='emacsclient -a "" -c' in ~/.emacs_anywhere/bin/emacstask with the equivalent with the full path, and I added

export EA_EDITOR='/usr/local/bin/emacsclient -a "" -c'

in my ~/.bash_profile. Nothing changed.
When I invoke the emacs anywhere service I get the following pop-up:

Screen Shot 2020-10-01 at 02 27 55

@LucaMarconato
Copy link

Any news on this? I am still stuck

@LucaMarconato
Copy link

Solved:

  1. I needed to add the permission for every app I want to use
  2. I changed EA_EDITOR to export EA_EDITOR='/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -a "" -c -d $DISPLAY'

@benlind
Copy link

benlind commented Dec 11, 2020

I use emacs-plus via homebrew along with zsh. I had to create a .bash_profile file with this line:

export EA_EDITOR='/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -a "" -c -d $DISPLAY'

@d1egoaz
Copy link

d1egoaz commented Jan 27, 2021

I was having again the same issue,
this time this worked for me:

https://apple.stackexchange.com/a/394983

Just open a terminal and run osascript -e 'tell application "System Events"' -e 'keystroke "echo hi"' -e end tell that will add system events to the list, even though I added it manually before 🤷

@jabirali
Copy link

Just open a terminal and run osascript -e 'tell application "System Events"' -e 'keystroke "echo hi"' -e end tell that will add system events to the list, even though I added it manually before 🤷

Just wanted to chime in that this worked for me as well, running emacs-plus@30 on MacOS Sonoma. Before that, I tried manually adding "Script Editor", "System Events", and "osascript" to System Settings > Privacy & Security > Accessibility, but none of these worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants