karlicoss / open-in-editor

Script to jump into files in you text editor, from your web browser
MIT License
9 stars 4 forks source link

Support OSX #1

Open karlicoss opened 4 years ago

karlicoss commented 4 years ago

This gives some examples, but I wonder if there is a simpler and more generic way...

I don't have a mac, so can't test anyway :(

alexriabtsev commented 4 years ago

I'm on macOS and would be glad to help you with development Trying to install and getting an error: python3 open_in_editor.py --install --editor default

Traceback (most recent call last):

File "open_in_editor.py", line 269, in <module> main() File "open_in_editor.py", line 263, in main install(editor=args.editor) File "open_in_editor.py", line 121, in install check_call(['desktop-file-validate', str(pp)]) File "/usr/local/Cellar/python@3.8/3.8.3_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 359, in check_call retcode = call(*popenargs, **kwargs) File "/usr/local/Cellar/python@3.8/3.8.3_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 340, in call with Popen(*popenargs, **kwargs) as p: File "/usr/local/Cellar/python@3.8/3.8.3_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 854, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/local/Cellar/python@3.8/3.8.3_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1702, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'desktop-file-validate'

karlicoss commented 4 years ago

Ah yeah, this 100% expected because osx is using a slightly different mechanism.

To fix this, install should check whether the system is linux or OSX (by checking platform.system() == 'Darwin')) and depending on the result, run install_linux and install_osx. As you can guess, install_osx needs to be written from scratch. I'd do it, but I don't have a mac nearby (and can't test on CI either because it doesn't have GUI).

alexriabtsev commented 4 years ago

which line(s) should I fix and test?

karlicoss commented 4 years ago

It's gonna be more than one line :) Basically you'd need a version of this method for OSX. If you manage to rewrite it completely so that it works with OSX, feel free to submit PR as is, I'll adjust the script so it picks the correct version.

Like I mentioned above, perhaps this link or some googling might help.

b1r3k commented 3 years ago

I'm trying to run promnesia in docker on raspberry pi. I'm getting this: /src/promnesia/src/promnesia/common.py:77: UserWarning: No xdg-mime on your OS! If you're on OSX, perhaps you can help me! https://github.com/karlicoss/open-in-editor/issues/1 xdg-mime is available in xdg-utils package but that has whole bunch of X-like dependencies. Will indexer work without that package?

karlicoss commented 3 years ago

Hey @b1r3k yeah, it's just a warning, indexer will totally work! I guess I could detect if X is available and if it's not then omit the warning altogether. The only thing that won't work is that clicking on a link to the file in the sidebar won't open the text editor directly (because the server in Docker can't open GUI apps, at least without some nasty hacks). But even that can work if the open-in-editor script is installed on the host system.

telotortium commented 2 years ago

On macOS, perhaps https://github.com/Lord-Kamina/SwiftDefaultApps will help? For example, I have set up an app at work named "Lark" to open "lark:" URLs using swda setHandler --URL lark --app /Applications/Lark.app. You can in turn create an App from a command-line script on macOS using https://sveinbjorn.org/platypus.

telotortium commented 2 years ago

I've hacked together a prototype that should allow this script to work on macOS.

  1. Create a file somewhere called open-in-editor (I put it in my home directory at /Users/bytedance/bin/open-in-editor) and put the following contents inside:
#!/usr/bin/env bash -l

# These 2 lines are useful for debugging - you can remove them later once you've debugged the script.
exec &>/tmp/open-in-editor.log
set -xv

python3 ~/misc/build/open-in-editor/open_in_editor.py --editor=emacs "$@"
rv=$?
sleep 1
ps -ef | grep '/Open In Editor$' | awk '{print $2}' | xargs kill
exit $rv

You should change the path ~/misc/build/open-in-editor/open_in_editor.py to wherever open_in_editor.py is on your system, and change --editor=emacs to what you want to use. Then run chmod +x open-in-editor on this file to make this an executable script.

  1. Download Open In Editor.platypus.txt, rename to Open in Editor.platypus.

  2. Install and open Platypus, then open the menu "Profiles > Load Profile..." and select the Open In Editor.platypus you just downloaded. Adjust paths to your script if necessary and then "Save Profile" to save the changes - saving the profile is the only way to edit this application if you need to fix a setting. Then click "Create App" and save it in your /Applications folder.

    You shouldn't need to change any of the other Platypus settings. In particular, you must leave "Remain running after execution" checked - this is why I kill all running Open In Editor processes in the open-in-editor script, so that you can launch the app again.

This should be all you need to get started. Let me know if you need some clarification on the instructions.

karlicoss commented 2 years ago

Oh wow, that's elaborate, thanks!