An open API service indexing awesome lists of open source software.

https://github.com/arvis-workflows/arvis-chrome-control

A JXA script and an Arvis Workflow for controlling Google Chrome
https://github.com/arvis-workflows/arvis-chrome-control

arvis arvis-workflow arvish chrome jxa

Last synced: 6 days ago
JSON representation

A JXA script and an Arvis Workflow for controlling Google Chrome

Awesome Lists containing this project

README

          

Chrome Control
==============

![Chrome Control](img/banner.png)

## 🔗 This workflow is converted from [alfred-workflow](https://github.com/bit2pixel/chrome-control).

* Note that there might be some code change or different actions from the original workflow.

* Marked original workflow's creator to author.

A JXA script and an Alfred Workflow for controlling Google Chrome
(Javascript for Automation).

This repository is forked from [chrome-control](https://github.com/bit2pixel/chrome-control)

Usage
-----

Make this file an executable
```sh
chmod +x ./chrome.js
```

Then run:
```sh
./chrome.js
```

> MacOS will ask you to allow permissions for this tool to control Chrome.
> Feel free to inspect the code before accepting.

Integration
-----------

You can use `chrome-control` to create fun integrations with your favorite tools (Alfred, vim, vscode, iterm2, ...).

### Chrome Control commands

Chrome Control commands:
- `tabs`: Lists all tabs
- `close url `: Close tabs with URLs matching these keywords
- `close title `: Close tabs with titles matching these keywords
- `dedup`: Close duplicate tabs

Commands
--------

### Close duplicate tabs

```sh
./chrome.js dedup
```

### Close all tabs by `titles` containing strings
> Strings are separated by spaces and `case insensitive`.

```sh
./chrome.js close --title "inbox" "iphone - apple"
```

```sh
./chrome.js close --title inbox iphone
```

### Close all tabs by `URLs` containing strings
> Strings are separated by spaces and `case insensitive`.

```sh
./chrome.js close --url "mail.google" "apple"
```

```sh
./chrome.js close --url google apple
```

### List all open tabs in all Chrome windows

```sh
./chrome.js list
```

The output is `JSON`, so you can pipe it to `jq`.
```sh
./chrome.js list | jq .
```

Returns a struct like this:

```json
{
"items": [
{
"title": "Inbox (1) - @gmail.com - Gmail",
"url": "https://mail.google.com/mail/u/0/#inbox",
"winIdx": 0,
"tabIdx": 0,
"arg": "0,0",
"subtitle": "https://mail.google.com/mail/u/0/#inbox"
},
{
"title": "iPhone - Apple",
"url": "https://www.apple.com/iphone/",
"winIdx": 0,
"tabIdx": 1,
"arg": "0,1",
"subtitle": "https://www.apple.com/iphone/"
}
]
}
```

> `arg` and `subtitle` are used for [Alfred](https://www.alfredapp.com/) integration.

### Close a specific tab in a specific window

> `Window Index` and `Tab Index` is the `arg` returned by the `list` command.

```js
./chrome.js close 0,13
```

### Focus on a specific tab in a specific window

```js
./chrome.js focus 0,13
```

### Show help

```sh
./chrome.js
```

### Don't prompt the user

`--yes` flag will cause no questions to be asked to the user. It'll close all tabs straight away.

> Attention: Use this with caution. Make sure you don't have any unsaved work, emails, ... etc.

### Prompt user in Chrome

`--ui` flag will cause the questions to be asked using a Chrome dialog instead of text in command line.

```sh
./chrome.js close --url apple --ui
```

## License

Copyright (c) 2019 Renan Cakirerk

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.