This Week's Sponsor:

Listen Later

Listen to Articles as Podcasts


A Better Chrome To Safari Bookmarklet

pythonista

pythonista

In January, I tried to put together a bookmarklet to send the webpage currently open in Google Chrome for iOS to Apple’s Safari. That turned out to be a surprisingly complex effort as Google didn’t think offering an “Open In Safari” option would be a good idea, and the app’s URL scheme produced some interesting results when opening and closing Chrome.

I was reminded of the bookmarklet this morning by reader @CNWLshadow, and I realized that I never posted the solution I settled with. It consists of a browser bookmarklet and a Pythonista script, and it works with just one tap.

With Pythonista 1.3, developer Ole Zorn added the possibility to open links specifically in Safari by prefixing them with safari-, therefore allowing me to create a simple bookmarklet that would:

  • Take the current URL open in Chrome;
  • Give it to Pythonista;
  • Open it in Safari.

The bookmarklet is extremely basic. It assumes a script called “ToSafari” is available in the root of Pythonista, and it sends an argument for the webpage that is currently open. You can copy the code below and add it to Chrome as a bookmark.

javascript:window.location='pythonista://ToSafari?action=run&argv='+encodeURIComponent(document.location.href);

The script is simple as well. It starts by counting the arguments sent to the script: if less than two, it will print that no URL was received; else, it will take the URL and send it to Safari by prefixing it with safari-.

# Receives a URL via JS bookmarklet and sends it to Safari
# Bookmarklet: javascript:window.location='pythonista://ToSafari?action=run&argv='+encodeURIComponent(document.location.href);
# Assumes script is in the root of Pythonista and called 'ToSafari'


import sys
import webbrowser

numArgs = len(sys.argv)

if numArgs < 2:
    print 'No URL was received'
    
else:
    url = sys.argv[1]

    webbrowser.open('safari-' + url)

Once set up, the script takes around 6 seconds to be executed on my iPad mini from a cold start (Pythonista force-quit from the multitasking tray), 1 second if Pythonista is in the background. While it isn’t the best solution, I think this is an acceptable compromise to get a working Chrome-to-Safari bookmarklet that doesn’t require any further manual operation.

Unlock More with Club MacStories

Founded in 2015, Club MacStories has delivered exclusive content every week for over six years.

In that time, members have enjoyed nearly 400 weekly and monthly newsletters packed with more of your favorite MacStories writing as well as Club-only podcasts, eBooks, discounts on apps, icons, and services. Join today, and you’ll get everything new that we publish every week, plus access to our entire archive of back issues and downloadable perks.

The Club expanded in 2021 with Club MacStories+ and Club Premier. Club MacStories+ members enjoy even more exclusive stories, a vibrant Discord community, a rotating roster of app discounts, and more. And, with Club Premier, you get everything we offer at every Club level plus an extended, ad-free version of our podcast AppStories that is delivered early each week in high-bitrate audio.

Choose the Club plan that’s right for you:

  • Club MacStories: Weekly and monthly newsletters via email and the web that are brimming with app collections, tips, automation workflows, longform writing, a Club-only podcast, periodic giveaways, and more;
  • Club MacStories+: Everything that Club MacStories offers, plus exclusive content like Federico’s Automation Academy and John’s Macintosh Desktop Experience, a powerful web app for searching and exploring over 6 years of content and creating custom RSS feeds of Club content, an active Discord community, and a rotating collection of discounts, and more;
  • Club Premier: Everything in from our other plans and AppStories+, an extended version of our flagship podcast that’s delivered early, ad-free, and in high-bitrate audio.