Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Alfred workflow to switch current active tab between Safari and Chrome.

License

Notifications You must be signed in to change notification settings

dearrrfish/browser-sugar-alfredworkflow

Repository files navigation

Browser Sugar Workflow for Alfred 2

Helper scripts playing with browser tabs, and more... Require OS X Yosemite+

Base Syntax

Actions: baction ; [option : value]; [notes|extras...]

Settings: bset action ; set_flag: flag set_value: value

  • action - keyword to trigger action, e.g. switch, unstash

  • flags - on/off value, e.g. clone

    • You can prepend prefix to flags to override default settings
      • @ - force flag being on state
      • ! - force flag being off state
      • priority: @ > ! > no prefix
  • option: value - key-value pairs of options, e.g. from: Google Chrome

  • notes | extras - additional text data, e.g. Stash Group Name on Feb 29

switch tabs between supported browsers

Syntax:

Action: bswitch [clone|dedupe|reverse]; [from:|to:|index:]

Set Default Flags: bset switch

Flags:

  • clone - Keep original tab(s) after switching
  • dedupe - Deduplicate URL in target browser before opening a new tab
  • reverse - Reverse lookups of source and target browsers

Options:

  • from - Source browser to switch tab(s) from, full application name or browser types
  • to - Target browser to switch tabs(s) to, full application name or browser types
  • index - Tab index number in the browser window to execute the workflow
    • Set index to all to switch all tabs, or use action modifier alt

copy specified data from Application/Browser/Tab(s)

Syntax:

Action: bcopy [url|title|selection|markdown|tabs] ; [from:|index:|format:]

Set Default Flags: bset copy

Flags:

  • url - Copy URL of target window/tab if available
  • title - Copy browser tab title or application window name
  • selection - Copy selected text in window/tab if available
  • markdown - Copy URL and title as a link in markdown syntax
  • tabs - Copy information of tabs in JSON string format

Options:

  • from - Source browser to switch tab(s) from, full application name or browser types
  • index - Tab index number in the browser window to execute the workflow
    • Set index to all to copy data from all tabs, or use action modifier alt
  • format - text formatting preset name used to generate copied text content, see User Files section below to see more details of the presets file.

open URL(s) from selection/clipboard

Syntax:

Action: bopen [dedupe] ; [in:]

Set Default Flags: bset open

Flags:

  • dedupe - Deduplicate URL in target browser before opening a new tab
    • Use action modifier alt can open all extracted URLs
  • search - Fallback to search when no URL was detected.

Options:

  • in - Target browser to open URL(s)

stash all tabs in browser window

Syntax:

Action: bstash [clone] ; [from:]; <stash group name>

Set Default Flags: bset stash

Flags:

  • clone - Do not close tabs after stashed them to group

Options:

  • from - Source browser to get the list of tabs to stash

Others:

  • stash group name - Group name saved in the stash file

unstash saved stashed tabs

Syntax:

Action: bunstash [clone] ; [to:]; <search>

Set Default Flags: bset unstash

Flags:

  • clone - Do not remove stash record after unstashed tabs

Options:

  • to - Target browser to restore tabs to

Others:

  • search - Search string to filter list of stashed groups

Customizations

User files

  • stash list - $USER_HOME/.config/bs-alfredworkflow/stash.json Auto-generated by workflow when necessary.

  • user config - $USER_HOME/.config/bs-alfredworkflow/config.json Auto-generated by workflow when necessary.

    • Can define lists of user browsers, and the first one of each group is considered as default, e.g.

      {
        "browsers": {
          "safari": ["Safari Technology Preview", "Safari"],
          "chrome": ["Google Chrome", "Google Chrome Canary", "Chromium"]
        }
        ...
      }

  • text formatting presets - $USER_HOME/.config/bs-alfredworkflow/formats.json Manually create if you want to utilize this feature.

    • basic scheme: { "preset_name": "format_string"}

    • wrapping flag with ## to represent the content in format string

    • flags not enabled in copy command but appearing in format_string will be skipped

    • example:

      {
          "markdown": "[##title##](##url##)",
          "custom1" : "##title## ##url##",
          "custom2" : "##title##\n##url##",
          "custom3" : "(##url## \"##title##\")"
      }

JXA script syntax

./<action>.js <preview|run|defaults|set> [flags] ; [options] ; [notes|extras] ; [overrides]

  • preview - Returns XML content of the query previews in Alfred
  • run - Execute the query of action
  • defaults - Returns XML content of the settings previews in Alfred
  • set - Set default on/off states of flags per action

Add Hotkey trigger

  1. Create new action from Actions - Run Script, choose language /bin/bash
  2. Write your own command with the call type of run, e.g. ./copy.js run "selection markdown; from: Safari"
  3. Assign a preferred trigger like a Hot Key, drag and connect trigger and action and output

Tips

  • For the result items of browser tabs shown in Alfred, press ⌘C to copy URL and title in markdown link format
  • ⌘L to see parsed query string, or error message, for debug use
  • ...

Todos

  • stash action to save/open multiple tabs at one time
  • Allow to specify source and target browser
  • Add delay and result validation between actions in command flow (Removed the feature of actions flow)
  • Firefox support
  • Configurations of default options/flags
  • Configurable notifications

Licences

MIT

Icons from iconfinder.com

About

Alfred workflow to switch current active tab between Safari and Chrome.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published