Using Applescript with Ghost Browser

AppleScript is a scripting language created by Apple which helps macOS users automate specific work processes. You can use AppleScript to automatically launch Ghost Browser in a particular profile, open a new tab in a chosen Identity or navigate tab to any URL.

To tell Ghost Browser to do something, you need to place the script inside the following statements:

tell application "Ghost Browser"
   <place script here>
end tell

Please note that this short article describes some basic constructions for Ghost Browser which can be compounded to produce more complex behavior (like in Example 2). It is not a full AppleScript guide and does not contain all the possibilities and variants of usage. 

Opening a browser window with AppleScript

To open a new window you can use the following AppleScript:

tell application "Ghost Browser"
  make new window
end tell

To open Ghost Browser window in a specific profile, you can use the following AppleScript:

tell application "Ghost Browser"
   make a new window with properties {profile: “<Profile name>”}
end tell

Where <Profile name> would be replaced with Default, Profile 1, etc. based on the folder name that contains the profile data. To check possible values go to the Ghost Browser user data folder:

/Users/<username>/Library/Application Support/GhostBrowser

And check folders such as “Default”, “Profile 1”, “Profile 2” and so on which correspond to your existing profiles.

Need help?  Contact us.

Opening a tab with AppleScript

Let’s assume that you already have running Ghost Browser and want to fill an existing window (that has id = 1) with tabs. To open a single tab in that window use the following code:

tell application "Ghost Browser"
   make a new tab at end of tabs of window 1 with properties {URL: “<site url>”, identity: “<identity id>”}
end tell

URL and identity tab properties are optional and can be omitted to default values. By default a new empty tab will be opened in the Default Identity. You can use the exact identity id or a constant to explicitly tell Ghost Browser how to open tabs. There are 2 predefined constants  “DEFAULT_IDENTITY” and “NEW_TEMPORARY_IDENTITY” to open a tab in the Default Identity or in a new Temporary Identity correspondingly.

Tab “identity” property can also be used to retrieve the actual identity id of the existing tab:

tell application "Ghost Browser"
  -- get identity id for first tab in window
  get identity of tab 1 of window 1
  -- get identity id for active (foreground) tab in window
  get identity of active tab of window 1
end tell

Usage Examples

Example 1. Open a new Ghost Browser window in a Default profile.

tell application "Ghost Browser"
   make a new window with properties {profile: “Default”}
end tell

Example 2. Open “https://ghostbrowser.com” site in different Identities. To shorten the code and to not duplicate windows index each tab creation we write the code in a slightly different structure.

tell application "Ghost Browser"
  tell window 1
    -- Open tab in Default Identity explicitly.
    make new tab with properties {URL:"https://ghostbrowser.com", identity:"DEFAULT_IDENTITY"}
    -- Open tab in a new Temporary Identity.
    make new tab with properties {URL:"https://ghostbrowser.com", identity:"NEW_TEMPORARY_IDENTITY"}		
    -- Add another tab to the previously created Temporary Identity.
    -- Thus, we get the last added (now active) tab identity id 
    -- and use it to create new tab
    tell active tab
	set var1 to identity
    end tell		
    make new tab with properties {URL:"https://ghostbrowser.com", identity:var1}
    -- Open tab in existing Permanent Identity
    make new tab with properties {URL:"https://ghostbrowser.com", identity:"52828322c4864c03a37e3aef2a6aace0"}
  end tell
end tell

How it looks in Script Editor:

The Result:

Need help? Contact us.