Frewacom/pywalfox

Fails to fetch pywal colors on Mac OS

jlioanag opened this issue · 27 comments

I set up pywalfox according to the installation guide but Firefox's theme colors do not change when the "Fetch Pywal colors" button is clicked.

In the browser console I got this: Error: Attempt to postMessage on disconnected port.

Any insight?

Look through the Troubleshooting section of the README if you have not already. As for the error you got, it is probably not related to Pywalfox.

If you go to the settings page of the addon and open the Debugging info dropdown, does it say ”Connected”?

Yes, it does say "Connected version not set".

Also, when I relaunched Firefox I got this message from the extension: The currently installed version of the browser extension does not support the installed native application. Not updating will most likely lead to unexpected behaviour and bugs.

EDIT: the native app is the most recent version

The issue you have seems quite similiar to #31.

Check if the path to the pywalfox executable is in your PATH and add it if is not. If that does not work you can try installing with sudo as described in the README.

I'm having the same issue.

macOS 10.15

brew cask install firefox
--> Installs Version 77.0.1 (64-bit)

Install pywalfox from the Add On Store

$ pip3 install --user pywalfox
--> Installs without error

$ pywalfox setup
Copied manifest to: /Users/<username>/Library/Application Support/Mozilla/NativeMessagingHosts/pywalfox.json
Set daemon executable path to: /Users/<username>/Library/Python/3.7/lib/python/site-packages/pywalfox/bin/main.sh
Set execute permissions on daemon executable
$ which pywalfox
/Users/brandon/Library/Python/3.7/bin/pywalfox
$ pywalfox -v
v2.4

Contents of pywalfox.json in /Users/<username>/Library/Application Support/Mozilla/NativeMessagingHosts

{
  "name": "pywalfox",
  "description": "Automatically theme your browser using the colors generated by Pywal",
  "path": "/Users/<username>/Library/Python/3.7/lib/python/site-packages/pywalfox/bin/main.sh",
  "type": "stdio",
  "allowed_extensions": [ "pywalfox@frewacom.org" ]
}

ls of /Users/<username>/.cache/wal

$ /bin/ls -lA ~/.cache/wal
total 240
-rw-r--r--    1 <username>  staff   128 Jun 29 17:47 colors
-rw-r--r--    1 <username>  staff   622 Jun 29 17:47 colors-kitty.conf
-rw-r--r--    1 <username>  staff   671 Jun 29 17:47 colors-konsole.colorscheme
-rw-r--r--    1 <username>  staff   238 Jun 29 17:47 colors-oomox
-rw-r--r--    1 <username>  staff   991 Jun 29 17:47 colors-putty.reg
-rw-r--r--    1 <username>  staff  3257 Jun 29 17:47 colors-rofi-dark.rasi
-rw-r--r--    1 <username>  staff  3257 Jun 29 17:47 colors-rofi-light.rasi
-rw-r--r--    1 <username>  staff   356 Jun 29 17:47 colors-speedcrunch.json
-rw-r--r--    1 <username>  staff   496 Jun 29 17:47 colors-sway
-rw-r--r--    1 <username>  staff   833 Jun 29 17:47 colors-tilix.json
-rw-r--r--    1 <username>  staff   531 Jun 29 17:47 colors-tty.sh
-rw-r--r--    1 <username>  staff   384 Jun 29 17:47 colors-vscode.json
-rw-r--r--    1 <username>  staff   203 Jun 29 17:47 colors-wal-dmenu.h
-rw-r--r--    1 <username>  staff   716 Jun 29 17:47 colors-wal-dwm.h
-rw-r--r--    1 <username>  staff   953 Jun 29 17:47 colors-wal-st.h
-rw-r--r--    1 <username>  staff   270 Jun 29 17:47 colors-wal-tabbed.h
-rw-r--r--    1 <username>  staff   609 Jun 29 17:47 colors-wal.vim
-rw-r--r--    1 <username>  staff   585 Jun 29 17:47 colors-waybar.css
-rw-r--r--    1 <username>  staff  1510 Jun 29 17:47 colors.Xresources
-rw-r--r--    1 <username>  staff   670 Jun 29 17:47 colors.css
-rw-r--r--    1 <username>  staff   977 Jun 29 17:47 colors.hs
-rw-r--r--    1 <username>  staff   759 Jun 29 17:47 colors.json
-rw-r--r--    1 <username>  staff   539 Jun 29 17:47 colors.scss
-rw-r--r--    1 <username>  staff   781 Jun 29 17:47 colors.sh
-rw-r--r--    1 <username>  staff   519 Jun 29 17:47 colors.styl
-rw-r--r--    1 <username>  staff   569 Jun 29 17:47 colors.yml
-rw-r--r--    1 <username>  staff   129 Jun 29 15:34 last_used_theme
drwxr-xr-x  118 <username>  staff  3776 Jun 29 17:47 schemes
-rw-r--r--    1 <username>  staff   414 Jun 29 17:47 sequences
-rw-r--r--    1 <username>  staff  2998 Jun 29 17:47 vivaldi.js
-rw-r--r--    1 <username>  staff   104 Jun 29 17:47 wal
$ pywalfox -p --verbose daemon
[06-29-2020 06:12:22] DEBUG:Using python 3.7.3
[06-29-2020 06:12:22] DEBUG:Firefox profile path is relative
[06-29-2020 06:12:22] DEBUG:Found chrome directory at path: /Users/<username>/Library/Application Support/Firefox/Profiles/to3p53b3.default-release/chrome
[06-29-2020 06:12:22] DEBUG:Setup socket server using AF_UNIX (linux/darwin)
[06-29-2020 06:12:22] DEBUG:Successfully bound socket to: /tmp/pywalfox_socket

I've tried installing pywalfox with sudo. In Debug it says "Connected version not set". Upon Firefox startup it asks me to update the daemon.

Any errors in the Browser console in Firefox?

Any errors in the Browser console in Firefox?

stderr output from native app pywalfox: /Users/<username>/Library/Python/2.7/lib/python/site-packages/pywalfox/bin/main.sh: line 3: pywalfox: command not found

Bingo. I had looked before, but must have missed it. I was able to resolve it by opening main.sh and explicitly setting the path to the output of which pywalfox.

/Users/<username>/Library/Python/2.7/bin/pywalfox

For some reason even though when I check any terminal (iTerm2 Terminal.app vscode ) with which pywalfox it appears, main.sh does not seem to know where it's at (maybe?). Thank you for leading me to that though and thanks for you work on this.

Edit (Guesses):

I think this has something to do with main.sh using the BASH environment. Since, 10.15 macOS has switched from BASH to ZSH. I am able to work around the issue by sourcing my .zshrc first. then running pywal daemon.

#!/usr/bin/env bash

source ~/.zshrc
pywalfox daemon

This also might be why sudo works for some people. Because it would put it in the $PATH everywhere (I think). In macOS however installing with sudo doesn't help because its still a different shell. My guess is that this would work normally on 10.14.

Yes, zsh and the bash shebang is most likely what is causing issues.

I should skip main.sh completely and point to the executable directly in the Firefox manifest. That should eliminate all PATH issues and probably close #31 and #33 as well.

I'm also experiencing a very similar issue, but I haven't had any luck with changing paths or anything like that. In the console of the extensions page I'm also seeing that Error: Attempt to postMessage on disconnected port message, and in the browser console I'm seeing Unchecked lastError value: Error: Could not establish connection. Receiving end does not exist. Is this the same issue, or do you think something different is going on here?

Could you try replacing this line in /Users/<username>/Library/Python/<python-version>/lib/python/site-packages/pywalfox/bin/main.sh (the path might be a bit different for you, but something like that):

pywalfox daemon

with

python -m pywalfox daemon || python3 -m pywalfox daemon || python2.7 -m pywalfox daemon

and see if that fixes it?

The way you installed Pywalfox should not make a difference, no.

The error you get when executing main.sh is expected since your python points to 2.7 which does not have Pywalfox installed. However, bash should then execute python3 -m pywalfox daemon (since the previous command failed) and it should work. The daemon did probably start (?), but you are not seeing any output, since the default settings will write all output to a log-file.

You could try re-running pywalfox setup and restarting your browser and see if that makes a difference. If not, could you take a screenshot of the Browser console?

Ok so I tried re-running pywalfox setup and restarting the browser but it didn't work, however I'm seeing the stderr output etc... error now instead, so I think that means progress has been made?
Screen Shot 2020-08-03 at 1 52 08 PM

Seems like it can not find pywalfox even if running with python3. Perhaps it could actually be because you installed with sudo python3. It seems like the python3 executable is used by Xcode and might not be the same as sudo python3?

Try reinstalling with python3 -m pip install pywalfox and pywalfox setup and see if that fixes it.

Ok so I re-installed it with those two command as suggested after running sudo pywalfox uninstall and sudo python3 -m pip uninstall pywalfox and these are the results. When using the default main.py I end up with this browser console:
Screen Shot 2020-08-03 at 2 02 59 PM
And when using the version modified with python -m pywalfox daemon || python3 -m pywalfox daemon || python2.7 -m pywalfox daemon I get this:
Screen Shot 2020-08-03 at 2 03 49 PM
Thanks for trying to give me a hand with this!

That is strange. What does which python3 return in your terminal?

/usr/local/bin/python3

Well, that seems to be the issue. For some reason python3 points to two different executables depending on if you run it from the terminal or via Firefox (/usr/local/bin/python3 and /Applications/Xcode.app/Contents/Developer/usr/bin/python3).

main.sh runs in bash, so could it be something in your .zshrc that is causing this?

You do not have to create a .zshrc. I just thought it was possible that something in there could cause this.

Any ideas as to why python3 points to two different executables? I am assuming that /usr/local/bin/python3 should be default and not the one Xcode provides.

If you can not figure it out, you can try installing Pywalfox using python/python2.7 instead.

That worked, thank you!!

Closing this for now, since this issue should be fixed in version >= 2.6.

Just an update on this. It still doesn't seem to work out of the box for me. Just test on a new computer. All I've done is installed python3 via homebrew and pywal via pip.

Some interesting information though. macOS defaults to zsh now, but going into bash or sh both show the same $PATH so everything is good there. pywalfox seems to live at /usr/local/bin/pywalfox

And if I run something like $(which pywalfox) start it does what is expected, but if I edit the main.sh script and add $(which pywalfox) start I get a command not found in the browser console. Oddly enough if I run the script it still executes as expected. It seems that when firefox calls it it's using a different PATH variable or something.

If I explicitly add /usr/local/bin/pywalfox start to main.sh it works as expected.

So then I got to thinking well if that works then if I explicitly add where my python is located which is currently /usr/local/opt/python@3.9/libexec/bin/python -m pywalfox start then it should work too. And it does. So the problem seems to be how firefox? is executing that main.sh not actually the commands like python2.7 start python start python3 start etc I'm not exactly sure how to figure out how to find python or pywalfox dynamically in this situation. It's no big deal I'm fine with just adding path explicitly, but I thought I'd update in case you might know whats going on.

Edit:
Possibly relevant on macOS https://scriptingosx.com/2018/02/setting-the-path-in-scripts/

Seems weird that Firefox would not find python, but honestly, I should just create a copy of main.sh during installation and set the absolute path dynamically. It feels like 90% of the issues people are having would be fixed if I did this. I am not sure why I have put it off for so long.

Thanks for the update though, I will look into it 👍

If you wanted something quick and dirty this would probably sort all the macOS users out.

#!/usr/bin/env bash

# Checks OS Version Number
macOS=$(sw_vers -productVersion)
if [[ ${#macOS} > 0  ]]; then
    PATH="$PATH:/usr/local/bin"
    pywalfox start
fi

python -m pywalfox start || python3 -m pywalfox start || python2.7 -m pywalfox start

The path variable is contextual on macOS apparently. (https://scriptingosx.com/2018/02/setting-the-path-in-scripts/)

hi i have the same problem!

im on the latest pywal version i believe (2.7.1) and i also get a 'connected version not set' in the debugging area.
i've tried deleting and re-installing, changing main.sh to the above and using bash instead of zsh but nothing works.

any help would be appreciated <3

hi i have the same problem!

im on the latest pywal version i believe (2.7.1) and i also get a 'connected version not set' in the debugging area.
i've tried deleting and re-installing, changing main.sh to the above and using bash instead of zsh but nothing works.

any help would be appreciated <3

Have you tried using the absolute path to the pywalfox executable in main.sh? As long as everything else is setup correctly by pywalfox install it should do the trick.

that worked !!! thank you:)