AppleScript – Executing JavaScript in Safari and Chrome

I haven’t used AppleScript much, but I was recently working on a script to automate a workflow and I was surprised to discover that each browser uses different commands to execute JavaScript.

Specifically, Safari uses do JavaScript "add code here" in document X and Chrome requires execute javascript "add code here"

Here’s an example of each:

Safari

tell application "Safari"
	open location "https://google.com"
	if (do JavaScript "document.readyState" in document 1) is "complete" then set pageLoaded to true
	display dialog pageLoaded as string
end tell

Google

tell application "Google Chrome"
     open location "https://google.com"
     if (execute javascript "document.readyState") is "complete" then set pageLoaded to true
     display dialog pageLoaded as string
end tell

A couple notes:

  1. AppleScript.app autocorrects the second example to a lowercase JavaScript, but either should work.
  2. Safari requires that a document is specified
  3. If you’re using Firefox, it’s currently not possible to execute JavaScript with AppleScript

Man-Made Wave

Man-made waves have existed for many years (as seen in the classic 80’s movie North Shore), but most of us doubted that we’d ever see anything that resembles a real wave.

Kelly Slater’s company has been working on creating a man-made wave for years and they recently released a video of a wave that shows a lot of promise.

Below is a video of Josh Kerr on one of his first waves in the new wave pool.

https://vimeo.com/165651682

Rumor has it that the wave pool is in the Fresno area. That’s only a couple hours from where I live, so I hope the rumors are true.

They haven’t released any other other details, but it’ll be interesting to see how they structure the pricing and control the crowds once it opens to the public.

Only the Essential: Pacific Crest Trail Documentary

Yet another Pacific Crest Trail (PCT) documentary to add to your list: Only the Essential: Pacific Crest Trail Documentary

The film was created by Casey Gannon and Colin Arisman during their 2013 thru-hiked of the Pacific Crest Trail.  The film is short (less than 40 minutes) and does a great job of capturing the spirit of the trail.

The narrator’s voice was a bit monotonic and some of the stop motion videos were nauseating, but overall I enjoy it. They captured some amazing footage of desert and the mountains and it was refreshing to see their enthusiasm throughout the journey. Even though hikers are documenting their trips in increasing numbers, I still enjoy watching most of them and see new facets of the trail in each one.

It’s embedded below, but you can also check it out on the Wild Confluence Films site.

Backpacking Documentaries

I’ve watched a lot of backpacking documentaries, but I think I have a new favorite: Do More With Less | A Conversation About The Pacific Crest Trail. I highly recommend it if you have any interest in backpacking or the Pacific Crest Trail. Here’s the full video:

Next up on my list is Tell it on the Mountain. The video download costs $15, but here’s a trailer:

If you have any favorite hiking or backpacking documentaries, please let me know.

Chrome Redirect Cache

I recently created a new site, but I visited the domain before the site and was redirected to a cgi default page. And as a result Chrome cached the URL as http://example.com/cgi-sys/defaultwebpage.cgi

After I got the site up and running, Chrome continued to redirect the domains to the cgi default page even though it was working properly in other browsers and an incognito Chrome window.

After a week or so of this annoyance, I searched the web for a solution and I found one on Sal Ferrarello’s site. It turns out that Chrome caches redirects and there isn’t a clear way to clear the redirect cache.

The solution that worked for me was Sal’s first idea to disable the cache from the Chrome Developer Tools. The easiest way to open the Developer Tools is Command Option I

Once the Developer Tools are open, click on the settings icon shown here:

Once the settings modal opens, check the box next to Disable Cache (while DevTools is open) option as shown here:

disable-cache

Now visit the page that is cached and the old redirect cache should be permanently removed.

Check out Sal’s post for more details.