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

Cannot view attachments on macOS #142

Closed
cravend opened this issue Sep 29, 2021 · 6 comments
Closed

Cannot view attachments on macOS #142

cravend opened this issue Sep 29, 2021 · 6 comments

Comments

@cravend
Copy link

cravend commented Sep 29, 2021

Hi y'all,

I'm having trouble opening attachments on macOS. originally, it was trying to call xdg-open (which I don't have installed), but even after changing to the default open command, I still get the following error:

Traceback (most recent call last):
  File "/usr/local/bin/scli", line 4461, in <module>
    main()
  File "/usr/local/bin/scli", line 4455, in main
    loop.run()
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/site-packages/urwid/main_loop.py", line 287, in run
    self._run()
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/site-packages/urwid/main_loop.py", line 385, in _run
    self.event_loop.run()
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/site-packages/urwid/main_loop.py", line 790, in run
    self._loop()
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/site-packages/urwid/main_loop.py", line 827, in _loop
    self._watch_files[fd]()
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/site-packages/urwid/raw_display.py", line 416, in <lambda>
    wrapper = lambda: self.parse_input(
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/site-packages/urwid/raw_display.py", line 515, in parse_input
    callback(processed, processed_codes)
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/site-packages/urwid/main_loop.py", line 412, in _update
    self.process_input(keys)
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/site-packages/urwid/main_loop.py", line 513, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "/usr/local/bin/scli", line 3359, in keypress
    key = super().keypress(size, key)
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/site-packages/urwid/container.py", line 1135, in keypress
    return self.body.keypress( (maxcol, remaining), key )
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/site-packages/urwid/container.py", line 2316, in keypress
    key = w.keypress((mc,) + size[1:], key)
  File "/usr/local/bin/scli", line 3277, in keypress
    key = super().keypress(size, key)
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/site-packages/urwid/container.py", line 1626, in keypress
    key = self.focus.keypress(tsize, key)
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/site-packages/urwid/container.py", line 2316, in keypress
    key = w.keypress((mc,) + size[1:], key)
  File "/usr/local/bin/scli", line 3043, in keypress
    key = super().keypress(size, key)
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/site-packages/urwid/container.py", line 1123, in keypress
    return self.footer.keypress((maxcol,),key)
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/site-packages/urwid/container.py", line 1626, in keypress
    key = self.focus.keypress(tsize, key)
  File "/usr/local/bin/scli", line 2622, in keypress
    return self._keypress_cmd_mode(key, key_orig, txt)
  File "/usr/local/bin/scli", line 2588, in _keypress_cmd_mode
    self._cmds.exec(cmd, *args)
  File "/usr/local/bin/scli", line 3438, in exec
    return fn(*args)
  File "/usr/local/bin/scli", line 3579, in open_last_attach
    if self.open_attach(txt.envelope):
  File "/usr/local/bin/scli", line 3574, in open_attach
    self.open_file(file_path)
  File "/usr/local/bin/scli", line 3565, in open_file
    return callf(cfg.open_command, {'%u': path}, background=True)
  File "/usr/local/bin/scli", line 94, in callf
    proc = subprocess.Popen(cmd, **subprocess_kwargs)
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Users/cravend/.pyenv/versions/3.9.6/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'open /Users/cravend/.local/share/signal-cli/attachments/VZcBkI9xUL5NJUMDMWKW'
@exquo
Copy link
Collaborator

exquo commented Sep 30, 2021

The open-command string needs to include a "placeholder" %u, which will be replaced with filenames at runtime:

--open-command='open "%u"'

The default open-command string is: xdg-open "%u"

This needs to be more clear to the users, though. I'll add some text to the error output to put anyone encountering this on the right track.

@cravend
Copy link
Author

cravend commented Sep 30, 2021

I have this line in my sclirc, does it not work that way?

open-command = 'open %u'

When I manually pass the open-command flag on the CLI, it works, but opens the attachment in TextEdit. EDIT: running the exact same command on the CLI directly works (i.e. opens with Preview).

Screenshot 2021-09-30 at 18 14 42

Screenshot 2021-09-30 at 18 14 29

@exquo
Copy link
Collaborator

exquo commented Sep 30, 2021

This config line should work:

open-command = open "%u"

When there are single quotes around the command, it is used as a single "two word" application name (not what you want). Without the double quotes around %u, the files with spaces in their names would not open.

Not sure about why TextEdit is launched instead of Preview.. Could you try running scli --debug and post the output of the logs (in ~/.local/share/scli/log) after opening an attachment?
Edit: I suspect maybe open is aliased to something in your .bashrc? scli does not read the aliases from it. You can try which open and /usr/bin/open <filename>.

@cravend
Copy link
Author

cravend commented Sep 30, 2021

The config line did work, thanks for the tip! The log is below. open isn't aliased to anything else; I also tried manually typing /usr/bin/open in the config but it didn't change.

My current theory is that open isn't recognising that the file is an image (because signal doesn't include the extension in the file).

I also realised that I was wrong — when I run open "/Users/cravend/.local/share/signal-cli/attachments/-jdUoOCZUCSwmM42eJbk", TextEdit opens (not Preview as expected). A potential workaround is to manually define the application used: open -a Preview "/Users/cravend/.local/share/signal-cli/attachments/-jdUoOCZUCSwmM42eJbk"

INFO:root:scli ?
DEBUG:root:signal-cli account: linked device
DEBUG:root:callf: `['signal-cli', '-u', '+[MY_PHONE]', '--output=json', 'daemon']`
DEBUG:root:callf: `['/usr/bin/open', '/Users/cravend/.local/share/signal-cli/attachments/-jdUoOCZUCSwmM42eJbk']`
INFO:root:daemon_log: INFO DaemonCommand - Exported dbus object: /org/asamk/Signal
INFO:root:signal-cli dbus service started
INFO:root:signal-cli 0.9.0

@exquo
Copy link
Collaborator

exquo commented Oct 1, 2021

signal-cli saves attachment files without extensions. If Mac's open relies only on file extensions to pick the appropriate application, it's not going to work.

The Preview app will only work with images (AFAIK), but attachments can also be audio or any other file type.

You'll need to either use an alternative to open like mimeopen that uses file inspection or other tricks, or roll your own equivalent.

@cravend
Copy link
Author

cravend commented Oct 1, 2021

Ah, I didn't even consider voice memos. I'll keep exploring alternatives on macOS and report back if I figure out a better option.

@exquo exquo closed this as completed in 1329e23 Oct 22, 2021
c-pec pushed a commit to c-pec/scli that referenced this issue Apr 20, 2022
Such as `--open-command='xdg-open "%u"'`

Closes isamert#142
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

2 participants