
OpenIn 4
Documentation - 08. JavaScript Editor for Rules
Table of content

Window
Working with the Script Editor
You can configure a test URL to work with and be able to run the script to see the Result and Console Log output.
Examples
Depending on the type of rule you are editing and which handler, you can find some examples in the menu list under the Script Editor.
Available objects
The ctx
object is available for the script.
With the following methods and properties:
url
- returns the URL objectgetSourceApp()
- returnsOpenContextSourceApp
object that can tell you if OpenIn recognized the application where the link was openedgetApps()
- returns the array of apps where OpenIn logic has already been applied, but you can override it (array ofOpenContextApp
)isForPrinting()
- (bool
) check if a file was requested to be opened for printinggetModifiers()
- returnsOpenContextModifiers
object that can tell which modifiers are pressed when a link or file was requested to be opened by the userisShareMenu()
- (bool
) check if the link was sent by the Share Menu “Open in OpenIn”isHandoff()
- (bool
) check if the link was sent by Handoff in OpenIngetFocusHint()
- (string
) get focus hint configured with the System Settings Focus (empty string if none is configured)
OpenContextSourceApp
provides the following properties:
path
- (string
) the path of the application that sent an open request
You can check if the opening app is Slack or another app. Just a note: when you open links from Slack, it is going to be a
different app that is under /Applications/Slack.app/...
, so to check if that is the Slack app, you want to check if this path starts with the Slack.app path.
OpenContextApp
provides the following properties:
name
- the name of the app (string
)running
- check if the app is running (bool
)bundleIdentifier
- the bundle identifier of the app (string
)visible
- (bool
) you can get or set this property, which is where you can apply your logic. For the list of apps that you are getting from OpenIn, you can configure which ones you want to see in the result list
URL
provides the following properties:
fragment
- everything after#
(string
)host
- hostname and port (string
)hostname
- just a domain, hostname (string
)href
- string representation of full URL (string
)username
- username (string
)password
- password (string
)pathname
- the path (string
)port
- port (string
)protocol
- scheme (string
)search
- query of the URL (string
)searchParams
- object to work on URL query (SearchParams
)
SearchParams
provides an object with the following methods:
append(name, value)
- append the search key valuedelete(name)
- delete all query items with the nameget(name)
- get the first value of the query with the namegetAll(name)
- get all values as an array of the query with the namehas(name)
- check if the query has a keyset(name, value)
- set the name and value for the searchkeys()
- get the array of all keys
OpenContextModifiers
provides an object with the following properties:
shift
- shift pressed (bool
)option
- option pressed (bool
)command
- command pressed (bool
)
Debugging
You can use console.log("test")
to write to the console output.
Examples
Example of a custom rule that makes decisions based on where the link is opened and domains:
(function() {
// the list of available apps to send link to
let apps = ctx.getApps()
// if the source app (where the link is opened) is Slack,
// keep only Safari as the visible app for OpenIn
// and because we will have only one app left,
// OpenIn will just open Safari
if (ctx.getSourceApp().path.startsWith("/Applications/Slack.app")) {
apps.forEach(function (app) {
app.visible = (app.name == "Safari")
})
return
}
// all loshadki.app URLs direct to Safari as well
if (url.hostname.endsWith("loshadki.app")) {
apps.forEach(function (app) {
app.visible = (app.name == "Safari")
})
return
}
// all google.com URLs direct to Safari and Chrome
if (url.hostname.endsWith("google.com")) {
apps.forEach(function (app) {
app.visible = ["Safari", "Google Chrome"].includes(app.name)
})
return
}
})()