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:
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.
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 .
/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
^
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).
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.
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.)