-
Notifications
You must be signed in to change notification settings - Fork 504
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 Mac - selecting a file in finder and trying to open it with Neovide opens an empty file #1259
Comments
I don't have mac device. |
It was relevant. That was about launching Neovide from finder (Mac file explorer). That one I worked around as you can see in my comment there. Now I'm trying to get Neovide to open a specific file, not just launch. It opens but doesn't load the file. |
Same issue here on MacOS 12.3.1 MacBook Pro (13-inch, M1, 2020) with Neovide 0.8.0. I can open Neovide.app as GUI and in shell, but I can't open a file in the finder, I get an empty buffer. |
i have macbook pro m1 and when i select js file to open with neovide i get empty buffer |
@younes-ghorbany For the last issue: See the option But that has nothing to do with this issue. Neovide can't know where you want to be when starting from the launcher. |
It would be really helpful for macOS to be able to open a file in new buffer by click. Does anyone know how to write this kind of AppleScript ?) |
@xbladesub This should work on run {input, parameters}
set filePath to quoted form of POSIX path of input
set neovide to "/usr/local/bin/neovide " -- path to neovide
do shell script neovide & filePath
return input
end run Just create a new application in automator and add this to the "run AppleScript" action. EDIT: the script only allows you to open one file at a time. I hacked together this other script that might solve it on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
on activate_open_instance(win_title, is_first_time)
tell application "System Events"
set neovideProcList to a reference to (every process whose name is "neovide")
repeat with proc in neovideProcList
set PID to proc's unix id
set myFiles to paragraphs of (do shell script "lsof -F -p " & PID & " | grep ^n/ | cut -c2-")
set fName to my replace_chars(win_title, "'", "")
if myFiles contains fName then
tell proc
set frontmost to true
end tell
return true
end if
end repeat
end tell
return false
end activate_open_instance
on run {input, parameters}
set filePath to quoted form of POSIX path of input
if not my activate_open_instance(filePath, false) then
set neovide to "/usr/local/bin/neovide "
do shell script neovide & filePath & " > /dev/null 2>&1 &"
delay 0.3
my activate_open_instance(filePath, true)
end if
return input
end run credits to https://gist.github.com/agzam/76d761804330cc8c4600fccda952ed1c |
@XLramones's solution didn't work for me with Here is the fixed version: on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
on activate_open_instance(win_title, is_first_time)
tell application "System Events"
set neovideProcList to a reference to (every process whose name is "neovide")
repeat with proc in neovideProcList
set PID to proc's unix id
set myFiles to paragraphs of (do shell script "lsof -F -p" & space & PID & space & "| grep ^n/ | cut -c2-")
set fName to my replace_chars(win_title, "'", "")
if myFiles contains fName then
tell proc
set frontmost to true
end tell
return true
end if
end repeat
end tell
return false
end activate_open_instance
on run {input, parameters}
set filePath to quoted form of POSIX path of input
if true or not my activate_open_instance(filePath, false) then
set enablePathVar to "eval \"$(/usr/libexec/path_helper -s)\"; PATH=$PATH:/opt/homebrew/bin neovide"
set cmd to "$(/usr/bin/env neovide)"
set fileCmdPath to quoted form of (filePath) & space & "> /dev/null 2>&1 &"
do shell script enablePathVar & space & cmd & space & fileCmdPath
delay 0.3
my activate_open_instance(filePath, true)
end if
return input
end run |
Your solution didn't work for me. I created the Applescript application, then used Open As -> and selected the application on a file. It opens up a blank Neovide window with the filename at the top and the correct file path, but the text area is always empty. Any ideas how to debug? |
@ThSGM I just tested again and I can confirm that it works. I streamlined the code a bit here though: on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
on activate_open_instance(win_title, is_first_time)
tell application "System Events"
set neovideProcList to a reference to (every process whose name is "neovide")
repeat with proc in neovideProcList
set PID to proc's unix id
set myFiles to paragraphs of (do shell script "lsof -F -p" & space & PID & space & "| grep ^n/ | cut -c2-")
set fName to my replace_chars(win_title, "'", "")
if myFiles contains fName then
tell proc
set frontmost to true
end tell
return true
end if
end repeat
end tell
return false
end activate_open_instance
on run {input, parameters}
set filePath to quoted form of POSIX path of input
if not my activate_open_instance(filePath, false) then
set enablePathVar to "eval \"$(/usr/libexec/path_helper -s)\"; PATH=$PATH:/opt/homebrew/bin;"
set cmd to "/usr/bin/env neovide"
set fileCmdPath to quoted form of filePath
do shell script enablePathVar & space & cmd & space & fileCmdPath
delay 0.3
my activate_open_instance(filePath, true)
end if
return input
end run Can you confirm that it works? |
Unfortunately it does not work. It launches neovide with a blank window. Is there a way to debug? |
@ThSGM What is the file path and name? Can you right click on the file, click on other and open it using the integrated finder to select the OpenInNeovide launcher. |
The file path is in ~/Downloads/ and the file name is listed in the top of the second image above. I create an Applescript Application file, then right click on the file, Open-As, and select the application file. |
For me it works when I slight change the code for the on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
on activate_open_instance(win_title, is_first_time)
tell application "System Events"
set neovideProcList to a reference to (every process whose name is "neovide")
repeat with proc in neovideProcList
set PID to proc's unix id
set myFiles to paragraphs of (do shell script "lsof -F -p" & space & PID & space & "| grep ^n/ | cut -c2-")
set fName to my replace_chars(win_title, "'", "")
if myFiles contains fName then
tell proc
set frontmost to true
end tell
return true
end if
end repeat
end tell
return false
end activate_open_instance
on run {input, parameters}
set filePath to quoted form of POSIX path of (input as text)
if true or not my activate_open_instance(filePath, false) then
set enablePathVar to "eval \"$(/usr/libexec/path_helper -s)\"; PATH=$PATH:/opt/homebrew/bin neovide"
set cmd to "$(/usr/bin/env neovide)"
set fileCmdPath to quoted form of (POSIX path of (input as text))
do shell script enablePathVar & space & cmd & space & fileCmdPath
delay 0.3
my activate_open_instance(filePath, true)
end if
return input
end run |
This is a duplicate of #1682 |
I use Here the script which I use to run #!/bin/bash
SERVICE="Neovide"
if pgrep -f "$SERVICE" >/dev/null
then
open /Users/nshv/Repos/neovide/target/release/bundle/osx/Neovide.app
else
export LUNARVIM_RUNTIME_DIR="${LUNARVIM_RUNTIME_DIR:-"$HOME/.local/share/lunarvim"}"
export LUNARVIM_CONFIG_DIR="${LUNARVIM_CONFIG_DIR:-"$HOME/.config/lvim"}"
export LUNARVIM_CACHE_DIR="${LUNARVIM_CACHE_DIR:-"$HOME/.cache/lvim"}"
cd $HOME
exec /Users/nshv/Repos/neovide/target/release/bundle/osx/Neovide.app/Contents/MacOS/neovide --frame=none -- -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" "$@"
# exec /Users/nshv/Repos/neovide/target/release/bundle/osx/Neovide.app/Contents/MacOS/neovide --frame=none --multigrid -- -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" "$@"
fi |
You can symlink the lunarvim directories to the normal spot, or import them in you Also, I think this belongs in discussions, but because you already asked here, dont remove it. |
So symlinking would be: ln -s ~/.local/share/lunarvim/lvim ~/.config/nvim This will allow neovide to open the config straight from the default directory. |
Awesome, that worked. Thanks |
Firstly, thanks to the previous contributors for your efforts. I found the script would fail if Neovide.app was opened without specifying any file or was specified with multiple files. I made a little bit changes to it to fix these scenarios: on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
on activate_open_instance(win_title, is_first_time)
tell application "System Events"
set neovideProcList to a reference to (every process whose name is "neovide")
repeat with proc in neovideProcList
set PID to proc's unix id
set myFiles to paragraphs of (do shell script "lsof -F -p" & space & PID & space & "| grep ^n/ | cut -c2-")
set fName to my replace_chars(win_title, "'", "")
if myFiles contains fName then
tell proc
set frontmost to true
end tell
return true
end if
end repeat
end tell
return false
end activate_open_instance
on run {input, parameters}
if input is not {} then
set posixPaths to {}
repeat with fileItem in input
set posixPath to POSIX path of (fileItem as text)
set end of posixPaths to quoted form of posixPath
end repeat
set AppleScript's text item delimiters to space
set filePathsString to (posixPaths as string)
set AppleScript's text item delimiters to ""
set firstPosixPath to item 1 of posixPaths
if true or not my activate_open_instance(firstPosixPath, false) then
set enablePathVar to "eval \"$(/usr/libexec/path_helper -s)\"; PATH=$PATH:/opt/homebrew/bin neovide"
set cmd to "$(/usr/bin/env neovide)"
do shell script enablePathVar & space & cmd & space & filePathsString
delay 0.3
my activate_open_instance(firstPosixPath, true)
end if
else
set enablePathVar to "eval \"$(/usr/libexec/path_helper -s)\"; PATH=$PATH:/opt/homebrew/bin neovide"
set cmd to "$(/usr/bin/env neovide)"
do shell script enablePathVar & space & cmd
delay 0.3
my activate_open_instance("", true)
end if
return input
end run |
Hello there. Since #1562 is closed for this issue and this issue is circling around an Apple script (thanx for that!), is there anything new for a clean solution? I think packaging as an appropriate MacOS app would be the best. |
I would love if someone could find out how we should do this properly (maybe package the scripts) and make them part of the install? There are also other scripts scattered around in different macOS related issues. Some of them even needed to make it work at all. So if someone could look if we should package some of that as well it would be good. For example I'm therefore adding the hacktoberfest tag. |
If you want to open a file from terminal, you can try
This open an empty file before, but somehow this suddenly works as well
Finder file: open with neovide Automator
Finder file open with... select the exported app |
A little detail for @leafOfTree 's idea, start the creation flow with
|
codeon replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
on activate_open_instance(win_title, is_first_time)
tell application "System Events"
set neovideProcList to a reference to (every process whose name is "neovide")
repeat with proc in neovideProcList
set PID to proc's unix id
set myFiles to paragraphs of (do shell script "lsof -F -p" & space & PID & space & "| grep ^n/ | cut -c2-")
set fName to my replace_chars(win_title, "'", "")
if myFiles contains fName then
tell proc
set frontmost to true
end tell
return true
end if
end repeat
end tell
return false
end activate_open_instance
on run {input, parameters}
if input is not {} then
set posixPaths to {}
repeat with fileItem in input
set posixPath to POSIX path of (fileItem as text)
set end of posixPaths to quoted form of posixPath
end repeat
set AppleScript's text item delimiters to space
set filePathsString to (posixPaths as string)
set AppleScript's text item delimiters to ""
set firstPosixPath to item 1 of posixPaths
if true or not my activate_open_instance(firstPosixPath, false) then
set enablePathVar to "eval \"$(/usr/libexec/path_helper -s)\"; PATH=$PATH:/opt/homebrew/bin neovide"
set cmd to "$(/usr/bin/env neovide)"
do shell script enablePathVar & space & cmd & space & filePathsString
delay 0.3
my activate_open_instance(firstPosixPath, true)
end if
else
set enablePathVar to "eval \"$(/usr/libexec/path_helper -s)\"; PATH=$PATH:/opt/homebrew/bin neovide"
set cmd to "$(/usr/bin/env neovide)"
do shell script enablePathVar & space & cmd
delay 0.3
my activate_open_instance("", true)
end if
return input
end run One thing not covered by the Application/AppleScript solution, is opening/adding another file in an already running Neovide. If someone knows if this would be possible somehow, it would be a nice addition. |
With 0.13, this issue does not occur anymore, probably due to #2395 |
Yes, we forgot to close the issues when merging that. |
Describe the bug
On Mac, selecting a file in finder and trying to open the file through right clicking the file and selecting Neovide as the application to open the file with, results with opening an empty file.
Also, Mac shows that it is uncertain that Neovide can open such a file.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Neovide should open with the selected file
Desktop (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: