cb_thunderlink icon indicating copy to clipboard operation
cb_thunderlink copied to clipboard

Full Mac Support?

Open sinewave opened this issue 4 years ago • 14 comments

Any chance clickable / OS support could make it into an upcoming release?

Having clickable links / OS support would be HUGE for me and the workflow I currently use!

I'm also having some difficult getting the Keyboard Shortcuts to work or perhaps I don't understand how to use them correctly. If I trigger the shortcut for configurable link 1 it doesn’t seem to copy to clipboard for me?

Lastly, would it be possible to add a shortcut to trigger the cb_thunderlink button action?

Thx

sinewave avatar Nov 12 '20 19:11 sinewave

@sinewave

I regret, but I have no knowledge about Mac, neither do I have access to it. I can explain what is needed. In a nutshell:

  • Native messaging set-up between thunderbird and an OS process.
  • An executable to be started when clicking on a link.

Both are very OS specific and someone with knowledge about that for Mac will need to jump in ...

Camiel B.

CamielBouchier avatar Nov 14 '20 10:11 CamielBouchier

I would support a macOS integration as well. I remember thunderlink had an integration, and I found this: link for instructions which uses an App to handle the links. Worth looking into. I'm going to try and see how this works so we can have cbthunderlink integration as well.

coolharsh55 avatar Jun 22 '21 21:06 coolharsh55

Reviewed and Working Setups:

  • 2021-11-22: cb_thunderlink v0.8.0 on macos Catalina and Monterey
  • 2023-08-04: cb_thunderlink v1.7.2 on macos 13.5 (Ventura) Intel or ARM CPU with Thunderbird 115.1.0 (Supernova)
  • 2024-06-20: cb_thunderlink v1.7.3 on macos 14.5 (Sonoma) Intel or ARM CPU with Thunderbird 115.12.1 (Supernova)

Here is how to install cb_thunderlink manually on macos:

  1. Download cb_thunderlink archive

    Using the git repository will allow you to track your changes and to merge with newer versions easily. Be careful where to place this repository. The ScriptEditor app that we are going to create below needs access to that directory. I prefer the home directory ($HOME) as things are not forgotten there.

    cd ~
    git clone https://github.com/CamielBouchier/cb_thunderlink
    cd cb_thunderlink
    CBDIR="$(pwd)"
    
  2. Set the execution bit on the python script

    cd "${CBDIR}"
    chmod +x cb_thunderlink.py
    
  3. Update location of the python script in the App JSON file

    Just replace the string cb_thunderlink.exe with the full path of the python script.

    cd "${CBDIR}"
    sed -i '' -e "s#cb_thunderlink.exe#${CBDIR}/cb_thunderlink.py#" cb_thunderlink.json
    
  4. Register App JSON file

    It took me a while to find the proper directory. After lots of browsing I found the correct location in the source code of openwith. In my case the directory did not exist and had to be created first.

    mkdir -p ~/Library/Mozilla/NativeMessagingHosts
    ( cd ~/Library/Mozilla/NativeMessagingHosts && ln -s "${CBDIR}/cb_thunderlink.json" )
    
  5. Create User Application Directory

    mkdir -p ~/Applications
    
  6. Launch Apple ScriptEditor

  7. In ScriptEditor paste the following script (possibly adapt for your CBDIR)

    I never used ScriptEditor before. It's very different from other programming languages. The script here works but this can be improved for sure.

    on open location givenURI
        try
            set prgpath to POSIX path of (path to home folder as string) & "/cb_thunderlink/cb_thunderlink.py"
            set quotedURI to quoted form of givenURI
        on error errMsg
            display dialog "ERROR: " & (name of me) & " failed to build command: " & errMsg
            return
        end try
        try
            do shell script prgpath & " " & quotedURI
        on error errMsg
            display dialog "ERROR: " & (name of me) & " failed to run: " & prgpath & " " & quotedURI & ": " & errMsg
        end try
    end open location
    
  8. In ScriptEditor press the small grey play button to verify the syntax

  9. In Script Editor save the Script as Application

    • File > Save...
    • Choose name CbThunderlink (extension app will be added automatically)
    • Choose directory ~/Applications
    • Choose File Format Application
  10. Register your new AppleScript App for URI scheme names cbthunderlink and thunderlink

    Use duti or SwiftDefaultApps

    I'm using homebrew to install additional software but you can also install both of these manually I guess. SwiftDefaultApps also has a GUI accessible through System Preferences.

    brew install --cask swiftdefaultappsprefpane
    SWDA="$(/bin/ls -1 $(brew --prefix)/Caskroom/swiftdefaultappsprefpane/*/swda | tail -1)"
    "${SWDA}" setHandler --app "${HOME}/Applications/CbThunderlink.app" --URL cbthunderlink
    "${SWDA}" setHandler --app "${HOME}/Applications/CbThunderlink.app" --URL thunderlink
    
  11. Download cb_thunderlink.xpi from the latest release of cb_thunderlink

    cd ~/Downloads
    XPI_URL="$(curl -s https://api.github.com/repos/CamielBouchier/cb_thunderlink/releases | grep browser_download_url | cut -d\" -f4 | head -1)"
    XPI_VERSION="$(echo "${XPI_URL}" | sed -e 's#.*/Release_##' -e 's#/.*##' )"
    curl -o "cb_thunderlink_${XPI_VERSION}.xpi" -L "${XPI_URL}"
    
  12. Install the xpi file

    Thunderbird > Tools > Addons and Themes > Gear Wheel Button > Install Addon from File...

    It is my understanding that you need the original xpi file as Thunderbird requires Addons to be signed. If you manually compose the xpi file (it's just a zip file) you will only be able to install as temporary addon.

Thank you Camiel for this wonderful addon.

baerbel2019 avatar Nov 22 '21 10:11 baerbel2019

Thanks a lot! I referred to this description in the documentation.

Camiel B


From: baerbel2019 @.*** Sent: Monday, November 22, 2021, 11:00 AM To: CamielBouchier/cb_thunderlink Cc: Camiel B; Comment Subject: [CamielBouchier/cb_thunderlink] Full Mac Support? (#12)

cb_thunderlink v0.8.0 works great on macos Catalina and Monterey. Here is how to install it:

Download cb_thunderlink archive

/Using the git repository will allow you to track your changes and
to merge with newer versions easily. Be careful where to place
this repository. The ScriptEditor app that we are going to create
below needs access to that directory. I prefer the home directory
($HOME) as things are not forgotten there./

cd  ~
git clonehttps://github.com/CamielBouchier/cb_thunderlink
cd  cb_thunderlink
CBDIR="$(pwd)"
Set the execution bit on the python script

cd  "${CBDIR}"
chmod +x cb_thunderlink.py
Update location of the python script in the App JSON file

/Just replace the string cb_thunderlink.exe with the full path of
the python script./

cd  "${CBDIR}"
sed -i''  -e"s#cb_thunderlink.exe#$CBDIR/cb_thunderlink.py#"  cb_thunderlink.json
Register App JSON file

/It took me a while to find the proper directory. After lots of
browsing I found the correct location in the source code of
openwith
<https://github.com/darktrojan/openwith/blob/master/webextension/native/open_with_mac.py#L48>.
In my case the directory did not exist and had to be created first./

mkdir -p~/Library/Mozilla/NativeMessagingHosts
(cd  ~/Library/Mozilla/NativeMessagingHosts&&  ln -s${CBDIR}/cb_thunderlink.json )
Create User Application Directory

mkdir -p~/Applications
Launch ScriptEditor
In ScriptEditor paste the following script (possibly adapt for
your CBDIR)

/I never used ScriptEditor before. It's very different from other
programming languages. The script here works but this can be
improved for sure./

on  open location  givenURI
     try
         set  prgpath  to  POSIX path  of  (path to  home folderas  string)&  "/cb_thunderlink/cb_thunderlink.py"
         set  quotedURI  to  quoted form  of  givenURI
     on error  errMsg
         display dialog  "ERROR: "  &  (name  of  me)&  " failed to build command: "  &  errMsg
         return
     end try
     try
         do shell script  prgpath&  " "  &  quotedURI
     on error  errMsg
         display dialog  "ERROR: "  &  (name  of  me)&  " failed to run: "  &  prgpath&  " "  &  quotedURI&  ": "  &  errMsg
     end try
end  open location
In ScriptEditor press the small grey play button to verify the syntax
In Script Editor save the Script as Application

  * |File| > |Save...|
  * Choose name |CbThunderlink| (extension app will be added
    automatically)
  * Choose directory |~/Applications|
  * Choose File Format |Application|
Register your new AppleScript App for URI scheme name |cbthunderlink|

Use duti <https://github.com/moretension/duti> or SwiftDefaultApps
<https://github.com/Lord-Kamina/SwiftDefaultApps>

/I'm using homebrew <https://brew.sh/> to install additional
software but you can also install both of these manually I guess.
SwiftDefaultApps also has a GUI accessible through |System
Preferences|./

brew install --cask swiftdefaultappsprefpane
SWDA="$(/bin/ls -1 /usr/local/Caskroom/swiftdefaultappsprefpane/*/swda
| tail -1)"
"${SWDA}"  setHandler --app"${HOME}/Applications/CbThunderlink.app"  --URL cbthunderlink
Download |cb_thunderlink.xpi| from the latest release of
cb_thunderlink
<https://github.com/CamielBouchier/cb_thunderlink/releases>

cd  ~/Downloads
CBLATEST="$(curl -s
https://api.github.com/repos/CamielBouchier/cb_thunderlink/releases
| grep browser_download_url | cut -d\" -f4 | head
curl -o - -L "${CBLATEST}" | bsdtar -xvf - --strip-components 1
"cb_thunderlink/cb_thunderlink.xpi"
Install the xpi file
<https://support.mozilla.org/en-US/kb/installing-addon-thunderbird>

|Thunderbird| > |Tools| > |Addons and Themes| > |Gear Wheel
Button| > |Install Addon from File...|

/It is my understanding that you need the original xpi file as
Thunderbird requires Addons to be signed
<https://blog.mozilla.org/addons/2016/01/22/add-on-signing-update/>.
If you manually compose the xpi file (it's just a zip file) you
will only be able to install as temporary addon./

Thank you Camiel for this wonderful addon.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/CamielBouchier/cb_thunderlink/issues/12#issuecomment-975351286, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARG7X2OMDZK63FCHVTRFSULUNIIFNANCNFSM4TTW67AQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

CamielBouchier avatar Dec 05 '21 10:12 CamielBouchier

Hi. I got the below error on macOS Ventura 13.2 with Thunderbird 102 and Python 3.11. This occurs on calling cb_thunderlink.py with the URL, clicking the thunderlink externally, putting the URL in a browser. I'm not sure whether this is something weird from macOS or there's something out of date in the above steps.

Traceback (most recent call last):
  File "/Users/harsh/apps/cb_thunderlink/./cb_thunderlink", line 211, in <module>
    send_socket.connect(server_address)
ConnectionRefusedError: [Errno 61] Connection refused

For now, I've set the cbthunderlink:// script handler to instead copy the link to clipboard and then I switch to thunderbird and click the cbthunderlink button - which does work. (thanks for the extension and the script - its really handy!)

coolharsh55 avatar Feb 07 '23 11:02 coolharsh55

@coolharsh55 I am really sorry, but this seems macOS specific. I have no access to a mac, neither do I intend to learn it. I can keep myself busy with Linux(es) and Windows.

O wait, if someone would send me a expensive nice mac to investigate and try, I might reconsider this position :)

Camiel B.

CamielBouchier avatar Feb 07 '23 18:02 CamielBouchier

@coolharsh55: Your error message means that the cb_thunderlink extension is not answering to requests. This is the case if either Thunderbird is not running or the extension has been disabled. In both cases you will get a popup window with the message you posted. Likely the same error message by cb_thunderlink.py will appear on other architectures.

baerbel2019 avatar Feb 07 '23 20:02 baerbel2019

@coolharsh55: Your error message means that the cb_thunderlink extension is not answering to requests. This is the case if either Thunderbird is not running or the extension has been disabled. In both cases you will get a popup window with the message you posted. Likely the same error message by cb_thunderlink.py will appear on other architectures.

Yes that makes sense of course. I was silently, but probably overly enthusiastically, assuming thunderbird and the extension was running in the first place ...

If the error occurs while this is the case, there might be other processes that seized the port, protection software intervening, etc ...

CamielBouchier avatar Feb 07 '23 20:02 CamielBouchier

Hi. Apologies, I should have clarified - thunderbird is running, cbthunderlink extension is running, and links work inside thunderbird i.e. copying the link to clipboard and clicking the cbthunderlink button inside thunderbird does open the email. So there seems to be a connection disruption from the script to the thunderbird/extension process. I can confirm this is macOS specific - the same setup works okay on Linux. I'll keep tinkering to see if I can figure out a solution as well.

coolharsh55 avatar Feb 07 '23 22:02 coolharsh55

Hi. Apologies, I should have clarified - thunderbird is running, cbthunderlink extension is running, and links work inside thunderbird i.e. copying the link to clipboard and clicking the cbthunderlink button inside thunderbird does open the email. So there seems to be a connection disruption from the script to the thunderbird/extension process. I can confirm this is macOS specific - the same setup works okay on Linux. I'll keep tinkering to see if I can figure out a solution as well.

Interesting. So my enthusiastic assumption was correct ... Just a few ideas (again, not having access or knowledge about macos makes them pretty random ...):

  • Do you have the issue after a fresh restart? I.e. is it not related to the one or the other process having blocked the socket/port/ ?
  • Any chance some proxy configuration is not playing nice with the socket communication?

CamielBouchier avatar Feb 07 '23 22:02 CamielBouchier

cb_thunderlink works for me on macOS Ventura 13.2 using Thunderbird 102.7. I can paste cbthunderlink://xxx URLs in both Firefox 109.0.1 and Safari 16.3.

Check the output of...

  • /usr/sbin/lsof -i :1302 - shows what process is listening on TCP port 1302 (should be Python)
  • lsof -Pp $(pgrep -f cb_thunderlink) | grep -i listen - shows TCP ports the python script is listening to
  • /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate - shows whether firewall is enabled
  • sudo pfctl -sa - shows firewall rules (and more)

baerbel2019 avatar Feb 07 '23 23:02 baerbel2019

I followed the instructions but stumbled on step 10 as the SWDA url was not working for me. Turns out that on my mac (running Venture) it is not /usr/local/... but /opt/homebrew/Caskroom/... Might be helpful for somebody.

cb_thunderlink v0.8.0 works great on macos Catalina and Monterey. Here is how to install it:

...

  1. Register your new AppleScript App for URI scheme names cbthunderlink and thunderlink Use duti or SwiftDefaultApps I'm using homebrew to install additional software but you can also install both of these manually I guess. SwiftDefaultApps also has a GUI accessible through System Preferences.
    brew install --cask swiftdefaultappsprefpane
    SWDA="$(/bin/ls -1 /usr/local/Caskroom/swiftdefaultappsprefpane/*/swda | tail -1)"
    "${SWDA}" setHandler --app "${HOME}/Applications/CbThunderlink.app" --URL cbthunderlink
    "${SWDA}" setHandler --app "${HOME}/Applications/CbThunderlink.app" --URL thunderlink
    

plur9 avatar Mar 29 '23 13:03 plur9

@plur9 Thanks for pointing this out! I modified the bad assignment in point 10 in my above comment to:

SWDA="$(/bin/ls -1 $(brew --prefix)/Caskroom/swiftdefaultappsprefpane/*/swda | tail -1)"

baerbel2019 avatar Aug 04 '23 19:08 baerbel2019

Sorry, this is beyond my horizon. It would be great if someone with a mac background could make this work for normal users. Pretty please 🙏🙏

paradeiser avatar Mar 15 '24 09:03 paradeiser