4

I like to open custom URLs, such as "myscheme://a/b/c" from my AppleScript code.

This is not about opening http URLs in a web browser. This is about getting the same result as when you create an .inetloc file in the Finder and then open that file in the Finder, or invoking this code in a macOS app written in ObjC:

[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString: @"myscheme://a/b/c"]];
2
  • With standard/normal AppleScript, open location "Opens a URL with the appropriate program.", other then that, maybe you'll have yo use Cocoa-AppleScript. Aug 1, 2017 at 20:38
  • Uh, indeed, open location seems to do the trick. I had searched quite a bit but could not find out about it. Care to turn that into an answer so that I can accept it? And perhaps explain where that's documented? Aug 2, 2017 at 21:57

1 Answer 1

6

If myscheme is properly registered in the Launch Services Database to open a particular application, then you can use the open location command, which: "Opens a URL with the appropriate program."

Use as in the following examples:

set theURL to "myscheme://a/b/c"

open location theURL

Or directly:

open location "myscheme://a/b/c"

Have a look at the AppleScript Language Guide and more specifically, the open location command.

3
  • 1
    Is there a way to open a URL in the background? Roughly the equivalent of the Terminal's open -g "$URL"? Dec 3, 2020 at 15:30
  • @BallpointBen did you come up with a solution?
    – codecowboy
    May 30, 2023 at 18:24
  • @codecowboy do shell script "open -g 'https://a/b/c'" May 30, 2023 at 19:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .