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

Macos open with doesnt work #1682

Open
ta3pks opened this issue Dec 19, 2022 · 31 comments
Open

Macos open with doesnt work #1682

ta3pks opened this issue Dec 19, 2022 · 31 comments
Labels
bug Something isn't working macos Specific to macOS and not investigable on other platforms

Comments

@ta3pks
Copy link

ta3pks commented Dec 19, 2022

Describe the bug
trying to open a file with neovide using open with opens an empty neovide instance on mac

To Reproduce
Steps to reproduce the behavior:

  1. right click a text file in finder
  2. hover "open with"
  3. select neovide to open with
  4. an empty neovide opens instead of the selected file

Expected behavior
selected file to open in neovide

Desktop (please complete the following information):

  • OS: macOS 13.1 ventura
  • Neovide Version 0.10.3
  • Neovim Version 0.8.1
@ta3pks ta3pks added the bug Something isn't working label Dec 19, 2022
@owittek
Copy link

owittek commented Dec 20, 2022

Does opening via Spotlight work? Might be related to my issue (#1679 (comment))

@girishji
Copy link

Same issue here.

  1. You can right click on a file in Finder, click "get info", change default application to Neovide. Then double click on the file, it opens empty buffer instead of said file.
  2. "open -a Neovide filename" should open filename, but it opens empty buffer. however "open -a Neovide --args filename" opens filename correctly.

@kabouzeid
Copy link

fyi this problem has been reported multiple times. +1 i would also like to have this. hopefully someday someone will make a PR for this

@ta3pks
Copy link
Author

ta3pks commented Jan 9, 2023

tried messing around a little creating a dummy project which is just

fn main() {
    let args: Vec<String> = std::env::args().collect();
    std::fs::write("/tmp/out.txt", args.join(" ")).unwrap();
}

then I bundled this using cargo bundle when I set it as default for any file and double click MacOS does not pass any extra arguments.
I have been researching about this whole night but every bit of info i could find on internet says macos does pass arguments.

If anybody can direct me to some piece of documentation i would be glad to open a pr about this

@girishji
Copy link

girishji commented Jan 9, 2023

Maybe the way neovide is bundled, it is ignoring the filename argument passed by macos when you set neovide as default application for opening a file. Instead it is looking for explicit arguments passed through 'open --args'.

@kabouzeid
Copy link

The Finder does not pass arguments. It uses Apple Events for this. This is because you can also open files in apps that are already running by dragging the file over the app icon in the dock.

@ta3pks
Copy link
Author

ta3pks commented Jan 11, 2023

I see let me see that route then @kabouzeid thanks for the info
Is it possible to reference the particular event name it would save me from reading whole bunch of things i will probably never need :)

@kabouzeid
Copy link

I have no idea. I wanted to fix this myself, then finally found out about Apple Events, and then lost interest :D

@ta3pks
Copy link
Author

ta3pks commented Jan 11, 2023

okay i will try to test thanks for the headers anyway :D

@ta3pks
Copy link
Author

ta3pks commented Feb 4, 2023

I figured getting filepath out before i open a pr wanted to ask which would be a better way to handle openFile events on mac

  1. wait until applicationDidFinishLaunching event and pass all files from openFile events as files_to_open flag into cmd_args and then actually do start_bridge, start_editor, create_window thus no extra stuff is needed since everything else works as before
  2. start everything and on every openFile event start a new buffer (somehow!. I dont know the neovide api to do this yet)

which would be a better way to handle macos doubleclick openfile requests and potentially future file clicks by user as the app runs?

@ta3pks
Copy link
Author

ta3pks commented Feb 4, 2023

I just dont understand how parts communicate on the entire codebase couldn't find anything that could potentially help me open a new buffer or send a raw command to neovim what am i missing here ?

@sharpenedblade
Copy link

sharpenedblade commented Feb 5, 2023

  1. wait until applicationDidFinishLaunching event and pass all files from openFile events as files_to_open flag into cmd_args and then actually do start_bridge, start_editor, create_window thus no extra stuff is needed since everything else works as before

This is probably the best approach, it would behave the same on all platforms.

  1. start everything and on every openFile event start a new buffer (somehow!. I dont know the neovide api to do this yet)

This would be the correct approach, but it would be better to implement this for all platforms, instead of having macos specific behavior.

which would be a better way to handle macos doubleclick openfile requests and potentially future file clicks by user as the app runs?

I think using the first approach is better right now, users would have a working open with implementation. We could revisit this later to implement the correct method, preferably for all platforms, at a later date.

@sharpenedblade
Copy link

I just dont understand how parts communicate on the entire codebase couldn't find anything that could potentially help me open a new buffer or send a raw command to neovim what am i missing here ?

I think the arguments are just passed to the nvim command.

@ta3pks
Copy link
Author

ta3pks commented Feb 6, 2023

@sharpenedblade the issue is that openfile event could come any moment after the app is opened so i think would be better to be able to listen throughout the life of neovide process however still i could not figure out how i exactly open new buffers from neovide in rust

@sharpenedblade
Copy link

@sharpenedblade the issue is that openfile event could come any moment after the app is opened so i think would be better to be able to listen throughout the life of neovide process however still i could not figure out how i exactly open new buffers from neovide in rust

If the user is opening a file using open or the finder button, and Neovide is closed, then the openfile event will occur during startup.

@ta3pks
Copy link
Author

ta3pks commented Feb 6, 2023

and if user clicks a file when a neovide process is already running then that process will receive the notification not a new one

@sharpenedblade
Copy link

sharpenedblade commented Feb 6, 2023

and if user clicks a file when a neovide process is already running then that process will receive the notification not a new one

I think it would be better to just handle it with the "naive" approach, then design a solution for all platforms. After this is working, then we could implement a system to handle new file opens on all platforms, and just handle openFile there. Building this entirely for macOS would mean rewriting code for other platforms(when we implement it). Implementing file opens after starting neovide would need consideration for the UI/UX, and it might need some changes in neovim too. It would also be better to get the opinion of one of the core maintainers before implementing something big like this.

@haidar47x
Copy link

haidar47x commented Jul 17, 2023

Same issue.

macOS: 13.4
Neovide: 0.10.4

By default, Neovide isn't enabled for supported files in the Application selection picker. Then, if we force the file to open with a Neovide, it results in an error:

The document “Output.txt” could not be opened. Neovide cannot open files in the “text” format.

It's pretty annoying. So, I switched to MacVim, which is rock solid.

@ta3pks
Copy link
Author

ta3pks commented Jul 18, 2023

Same issue.

macOS: 13.4 Neovide: 0.10.4

By default, Neovide isn't enabled for supported files in the Application selection picker. Then, if we force the file to open with a Neovide, it results in an error:

The document “Output.txt” could not be opened. Neovide cannot open files in the “text” format.

It's pretty annoying. So, I switched to MacVim, which is rock solid.

MacVim is just vim not neovim isnt it? also neovide comes with some pretty cool animations besides its a community project so I dont think your approach of treating it as a product is correct

@fredizzimo
Copy link
Member

If you are still wondering about the implementation, you should be able to to use the ParallelCommand::FileDrop that we already have and use here

neovide/src/window/mod.rs

Lines 199 to 205 in eeac6e7

Event::WindowEvent {
event: WindowEvent::DroppedFile(path),
..
} => {
let file_path = path.into_os_string().into_string().unwrap();
EVENT_AGGREGATOR.send(UiCommand::Parallel(ParallelCommand::FileDrop(file_path)));
}

You just need to wait until Neovim has launched and accepts commands before calling it.

@haidar47x
Copy link

haidar47x commented Jul 18, 2023

MacVim is just vim not neovim isnt it? also neovide comes with some pretty cool animations besides its a community project so I dont think your approach of treating it as a product is correct

You're right. It uses Vim but it integrates very well with the macOS ecosystem. Neovide does offer some cool features, but the presence of a few minor bugs makes it unusable for me.

I wish I knew Rust, I would have helped. :/

Edit: Grammar

@9mm
Copy link
Contributor

9mm commented Dec 21, 2023

I think i see the problem. It looks like the dropped file event only applies to dragging into the window, NOT the dock icon. Looking now at winit to see if theres some new event or something

@fredizzimo fredizzimo added the macos Specific to macOS and not investigable on other platforms label Jan 13, 2024
@abhillman
Copy link
Contributor

Same issue here.

  1. You can right click on a file in Finder, click "get info", change default application to Neovide. Then double click on the file, it opens empty buffer instead of said file.
  2. "open -a Neovide filename" should open filename, but it opens empty buffer. however "open -a Neovide --args filename" opens filename correctly.

Indeed, the issue appears to be that whereas --args passes the path to main(...) open -a Neovide <path> does not.

From the man page for OPEN(1) (i.e. man open):

     --args
         All remaining arguments are passed to the opened application in the argv parameter to main().
         These arguments are not opened or interpreted by the open tool.

@abhillman
Copy link
Contributor

Related PR #2191

@bogado
Copy link

bogado commented Feb 22, 2024

Here I get a "Neovide" cannot open files in the "text" format. That is ironic to say the least.

I do believe that this most be some missing key on a configuration of the application. Basically directing the OS that Neovide can open "text" and other types of files.

image

@bogado
Copy link

bogado commented Feb 22, 2024

I can drag and drop files once the window is open though.

@brnt
Copy link

brnt commented Mar 13, 2024

Same issue. I can open files directly from the console with:

$ neovide foo.md

I can also drag files onto an existing neovide window and they open correctly, but neither "Open with..." nor double-clicking (with handler set to neovide) works. I get an empty neovide buffer.

Side note @bogado, I added this snippet to Info.plist and now neovide is recognized as a handler for all text-ish files.

  <key>CFBundleDocumentTypes</key>
  <array>
    <dict>
      <key>CFBundleTypeName</key>
      <string>All Text Files</string>
      <key>LSItemContentTypes</key>
      <array>
          <string>public.text</string>
      </array>
      <key>LSHandlerRank</key>
      <string>Owner</string>
    </dict>
  </array>

@brnt
Copy link

brnt commented Mar 13, 2024

Looks like @polachok 's PR may address the open-from-finder problem. Fingers crossed...

@fredizzimo
Copy link
Member

@garymh
Copy link

garymh commented May 18, 2024

I still can't seem to get macOS to see Neovide as something that can open text files... I can right click and select "Get Info" and find it through the menu, but I need to click "All Applications" and still get a warning.
Screenshot 2024-05-18 at 09 18 24

I also use OpenIn which is having problems as a result when I set Neovide as the text file opener:
Screenshot 2024-05-18 at 09 16 52

@fredizzimo
Copy link
Member

Ok, re-opening this.

@polachok

@fredizzimo fredizzimo reopened this May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working macos Specific to macOS and not investigable on other platforms
Projects
None yet
Development

No branches or pull requests