Toggle between Safari Technology Preview and normal Safari (or between any browsers)

[Continuing the discussion from Select a different browser under certain conditions:]


Yesterday Apple made the Safari Technology Preview available.

For quickly toggling your default browser between ‘Safari’ and ‘Safari Technology Preview’ I have modified the Chrome/Safari toggle macro a bit:

Default Browser Toggle (STP).kmmacros (6.1 KB)


Note: The change of the default http handler causes the system to bring up a confirmation dialog. This dialog gets dismissed by the AppleScript (credits to @ccstone) in the last group. In this version I’ve added a notification that shows the actually set default browser after the toggle.

If you do want to see the confirmation dialog you can disable the last group. This will also deactivate the notification.


In case you want to toggle between other browsers you find some bundle identifiers in the comment of the macro. To get a quick and dirty list of all available browsers (http handlers) on your Mac you can execute the action beneath the comment. It will output something like this:

2 Likes

Update, ver 1.0.2 (2016-10-06)

  • The AppleScript now performs a direct button press instead of setting focus and pressing Space
  • Added a wait (repeat) loop, since the preceding Swift script may take a couple of seconds to launch.
  • Added timeout to the AppleScript.

Default Browser Toggle (STP).kmmacros (7.0 KB)

You can use the script to toggle between other browsers, too. For example, to toggle between Safari and Firefox replace com.apple.SafariTechnologyPreview in the Swift script with org.mozilla.firefox.

Update, ver 1.0.1 (2016-08-27):

The script now tests for the installed Swift version, und thus should run fine with any of these versions:

  • Swift 2.2 (current release version, Xcode 7 / macOS El Capitan)
  • Swift 2.3 (next release version, Xcode 8 / macOS Sierra)
  • Swift 3.0 (current beta version, Xcode 8)

Other changes:

  • Prettified the output of the available-http-handlers test script.
  • Prettified the notification.

Default Browser Toggle (STP).kmmacros (7.3 KB) — 2016-08-27

Update (2016-08-10):

Compatibility with Swift 3:

Default Browser Toggle (STP) [Swift 3].kmmacros (7.1 KB)

Is the context of this pre-Sierra ?

I may well be mistaken, but I think I had assumed that the technology preview version had now been released, at least on Sierra, as Safari 10.

I thought Safari 10beta had been released as Safari 10, but I might be mistaken, too.

Here are links for both, STP for El Capitan and STP for Sierra.

STP is definitively not the same as the current Safari 10. Compare on html5test.com.

1 Like

Update, ver 1.0.4 (2020-03-07)

  • Updated for Swift 5
  • Removed fallback code for Swift 2 and 3
  • Added error checks
  • Notification now shows app version and path

Screen Shot 2020-03-07 at 14.10.12-pty-fs8

Default Browser Toggle (Safari:STP) - 1.0.4 <F948 200307T142203>-pty-fs8
Default Browser Toggle (Safari:STP) - 1.0.4 <F948 200307T142203>.kmmacros (10.0 KB)

You can use the macro also to toggle between other browsers than Safari and STP. For example, to toggle between Safari and Firefox replace com.apple.SafariTechnologyPreview in the Swift script with org.mozilla.firefox .

I changed com.apple.SafariTechnologyPreview to com.google.Chrome in the first script box and it does not seem to work

Here is the result of the first script:

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2/libxml/module.modulemap:1:8: error: redefinition of module 'libxml2'
module libxml2 [system] [extern_c] {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2/module.modulemap:1:8: note: previously defined here
module libxml2 [system] [extern_c] {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2/libxml/module.modulemap:1:8: error: redefinition of module 'libxml2'
module libxml2 [system] [extern_c] {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2/module.modulemap:1:8: note: previously defined here
module libxml2 [system] [extern_c] {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFStream.h:20:10: note: while building module 'Dispatch' imported from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFStream.h:20:
#include <dispatch/dispatch.h>
^
:1:9: note: in file included from :1:
#import "dispatch.h"
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/dispatch/dispatch.h:59:10: error: could not build module 'os_object'
#include <os/object.h>
^
:1:9: note: in file included from :1:
#import "Headers/CoreFoundation.h"
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:60:10: note: in file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:60:
#include <CoreFoundation/CFPropertyList.h>
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFPropertyList.h:17:10: note: in file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFPropertyList.h:17:
#include <CoreFoundation/CFStream.h>
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFStream.h:20:10: error: could not build module 'Dispatch'
#include <dispatch/dispatch.h>
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/swift/CoreFoundation.swiftmodule/x86_64.swiftinterface:4:19: error: could not build Objective-C module 'CoreFoundation'
@_exported import CoreFoundation
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/swift/Foundation.swiftmodule/x86_64.swiftinterface:5:8: error: failed to load module 'CoreFoundation'
import CoreFoundation
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2/libxml/module.modulemap:1:8: error: redefinition of module 'libxml2'
module libxml2 [system] [extern_c] {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2/module.modulemap:1:8: note: previously defined here
module libxml2 [system] [extern_c] {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2/libxml/module.modulemap:1:8: error: redefinition of module 'libxml2'
module libxml2 [system] [extern_c] {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2/module.modulemap:1:8: note: previously defined here
module libxml2 [system] [extern_c] {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGBase.h:12:10: note: while building module 'CoreFoundation' imported from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGBase.h:12:
#include <CoreFoundation/CFBase.h>
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFStream.h:20:10: note: while building module 'Dispatch' imported from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFStream.h:20:
#include <dispatch/dispatch.h>
^
:1:9: note: in file included from :1:
#import "dispatch.h"
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/dispatch/dispatch.h:59:10: error: could not build module 'os_object'
#include <os/object.h>
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGBase.h:12:10: note: while building module 'CoreFoundation' imported from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGBase.h:12:
#include <CoreFoundation/CFBase.h>
^
:1:9: note: in file included from :1:
#import "Headers/CoreFoundation.h"
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:60:10: note: in file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:60:
#include <CoreFoundation/CFPropertyList.h>
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFPropertyList.h:17:10: note: in file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFPropertyList.h:17:
#include <CoreFoundation/CFStream.h>
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFStream.h:20:10: error: could not build module 'Dispatch'
#include <dispatch/dispatch.h>
^
:1:9: note: in file included from :1:
#import "Headers/CoreGraphics.h"
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h:8:10: note: in file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h:8:
#include <CoreGraphics/CGBase.h>
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGBase.h:12:10: error: could not build module 'CoreFoundation'
#include <CoreFoundation/CFBase.h>
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGDisplayConfiguration.h:12:10: note: while building module 'IOKit' imported from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreGraphics.framework/Headers/CGDisplayConfiguration.h:12:
#include <IOKit/IOKitLib.h>
^
:4:9: note: in file included from :4:
#import "Headers/IOCFBundle.h"
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOCFBundle.h:26:10: error: could not build module 'CoreFoundation'
#include <CoreFoundation/CoreFoundation.h>
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/swift/CoreGraphics.swiftmodule/x86_64.swiftinterface:4:19: error: could not build Objective-C module 'CoreGraphics'
@_exported import CoreGraphics
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2/libxml/module.modulemap:1:8: error: redefinition of module 'libxml2'
module libxml2 [system] [extern_c] {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2/module.modulemap:1:8: note: previously defined here
module libxml2 [system] [extern_c] {
^
:1:9: note: in file included from :1:
#import "dispatch.h"
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/Dispatch/dispatch.h:59:10: error: could not build module 'os_object'
#include <os/object.h>
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/swift/Dispatch.swiftmodule/x86_64.swiftinterface:5:19: error: could not build Objective-C module 'Dispatch'
@_exported import Dispatch
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2/libxml/module.modulemap:1:8: error: redefinition of module 'libxml2'
module libxml2 [system] [extern_c] {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2/module.modulemap:1:8: note: previously defined here
module libxml2 [system] [extern_c] {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2/libxml/module.modulemap:1:8: error: redefinition of module 'libxml2'
module libxml2 [system] [extern_c] {
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2/module.modulemap:1:8: note: previously defined here
module libxml2 [system] [extern_c] {
^
/var/folders/5s/z93_cwq919q4snkq9k9qs6k40000gn/T/Keyboard-Maestro-Script-214B6A46-0CEE-49AB-957F-E3BA3C41B7D1:1:8: error: failed to load module 'Foundation'
import Foundation
^

Works fine here.

with this in the first relevant Swift Script action:

import Foundation

LSSetDefaultHandlerForURLScheme("http" as CFString, "com.google.Chrome" as CFString)
LSSetDefaultHandlerForURLScheme("http" as CFString, "com.apple.safari" as CFString)

You have downloaded the latest version of the macro, right? And your system is up to date? (Especially no legacy Xcode).

Tom,

My bad - I downloaded XCode, but did not open/install it :frowning:
It works perfectly as intended now.

Thanks!
b

1 Like

Thanks for the feedback. Glad that it works now!

Based on the above feedback by @sudelb :

To have this macro running, it is necessary to have a working (and lastest) Swift runtime running on your system. (I hadn’t considered this before, I was stupidly assuming everybody had a current Xcode installed. My bad.)

The easiest way to do this, is to install the current Xcode via Mac AppStore.

If you already had Xcode versions installed before that, they should get overwritten automatically.

If not (for example you opted to maintain several different versions), check out which one is the actually preferred Xcode version by the system:

xcode-select -p

This should show which Xcode versions are present on your system.

In order to designate a specific Xcode version as your “preferred one”, just do this:

xcode-select <path to your Xcode version>

You may have to use sudo.

You do not have to select the Developers directory, by the way.

And, as said, if you only have one Xcode installed, or you just have installed it the very first time, this should not be necessary at all.

Makes sense, thank you!

I have to thank you, because I have missed the fact, that many people have not installed Xcode at all.

Actually, the more interesting question: Is there a way (besides installing the whole Xcode thingy (5+GB) to get a a working Swift runtime? (So that users can execute Swift scripts, I mean.)

I’m a bit outdated. With Swift 2 (or 3) there hasn’t been any – IIRC. Has anything been added afterwards? (Question to the Swift Pros here.)

@peternlewis, any insight on this? Or @ComplexPoint ?