Coder Social home page Coder Social logo

bit2pixel / chrome-control Goto Github PK

View Code? Open in Web Editor NEW
189.0 7.0 25.0 1.55 MB

A JXA script and an Alfred Workflow for controlling Google Chrome

Home Page: https://medium.com/@bit2pixel/how-i-navigate-hundreds-of-tabs-on-chrome-with-jxa-and-alfred-9bbf971af02b

License: MIT License

JavaScript 100.00%
jxa javascript alfred alfred-workflow chrome

chrome-control's Introduction

Chrome Control

Chrome Control

A JXA script and an Alfred Workflow for controlling Google Chrome (Javascript for Automation). Also see my How I Navigate Hundreds of Tabs on Chrome with JXA and Alfred article if you're interested in learning how I created the workflow.

Usage

Make this file an executable

chmod +x ./chrome.js

Then run:

./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, ...).

Alfred

I've created an Alfred Workflow to use Chrome Control. You can find it under the intergrations directory.

Alfred Chrome Control commands:

  • tabs: Lists all tabs
  • close url <keywords>: Close tabs with URLs matching these keywords
  • close title <keywords>: Close tabs with titles matching these keywords
  • dedup: Close duplicate tabs

Alfred

Commands

Close duplicate tabs

./chrome.js dedup

Close all tabs by titles containing strings

Strings are separated by spaces and case insensitive.

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

Close all tabs by URLs containing strings

Strings are separated by spaces and case insensitive.

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

List all open tabs in all Chrome windows

./chrome.js list

The output is JSON, so you can pipe it to jq.

./chrome.js list | jq .

Returns a struct like this:

{
  "items": [
    {
      "title": "Inbox (1) - <hidden>@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 integration.

Close a specific tab in a specific window

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

./chrome.js close 0,13

Focus on a specific tab in a specific window

./chrome.js focus 0,13

Show help

./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.

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

Dialog

How did you create the banner and icon?

It took around 4 hours using Photoshop. I wanted to use Illustrator but I realized that I completely forgot how to use it.

Drawing the shapes are pretty easy but I spent most of the time on the following:

  • Picking harmonious colors.
  • Figuring out how to make it less dull, ended up using a shadow under the window which made a significant difference.
  • Figuring out how to represent the infrared waves.
  • Finding a way to export the PNG to ICNS.

Planning to write an article on that soon.

Bug Fixes & Pull Requests

If you find any bugs please feel to create an issue or create a pull request.

I can only accept pull requests to the source code and not the binary files for ensuring the repo stays sanitized. If you have any feature requests for the workflow, I'd be happy to add them in after a discussion.

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.

chrome-control's People

Contributors

anthopakpak avatar bit2pixel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

chrome-control's Issues

Add modifier to Copy URL to Clipboard?

Would it be possible to add a modifier to allow the user to copy a tab's URL to the clipboard?

This workflow is really great, thanks for making it. No pressure to add features on my account! 😄

Add ability to queue multiple tabs to be closed

It would be nice if we were able to queue up multiple tabs to be closed, similar to how you can queue up multiple files in Alfred.

It could be easier to close a lot of different tabs using Alfred than it is using Chrome to do the same, but only if we didn't have to action tabs individually.

I'm not sure how this could be done, but it's just an idea and possible enhancement.

Does not work on Big Sur beta

Hi! Just installed Big Sur beta, already regretting it :-) Chrome control Alfred workflow used to work fine before updating. How it returns an empty list of tabs. I tried running "./chrome.js list" in Terminal and got

./chrome.js: execution error: Error: TypeError: undefined is not an object (evaluating '$.NSFileHandle.fileHandleWithStandardOutput') (-2700)

Feature Request: Support chromium browser

Microsoft Edge is a browser with chromium kernel, so chrome-control supports it too. The only change is Application('Google Chrome') to Application('Microsoft Edge') .

Maybe chrome-control can support this by allowing the user to specify variable application name, like CHROMIUM_APPLICATION_NAME=Microsoft Edge.

image

Feature Request: Fuzzy search on URLs

First off, thanks a trill for this!

I found an issue when trying to switch to my SoundCloud tab:

  1. I'd type tab sound
  2. Nothing would appear because SoundCloud replaces the tab title with the current track title

I expect:

  1. I type tab sound
  2. The workflow will fuzzy search the URL soundcloud.com and return that tab 😄

Expand to use work with other browsers

I was wondering if you thought about how this might be expanded to be work with other browsers? I've just started using this for a few days and looks like it will work great for my purposes.

Any way to improve list efficiency?

Hi!

First, thanks a lot for this awesome Alfred workflow, I really enjoy using it! 👌
The only thing I struggle with is the fact that listing the tabs is too slow. I have hundreds of opened tabs and it takes several seconds before showing the tabs list (sometimes up to 10seconds). So unfortunately, I lose a lot of time waiting the loading…

I've looked at the code, but from what I see the logic is nice, and I don't see a straightforward way to improve the efficiency. I guess the slow part is the looping through windows/tabs, but I can't find a better way to do it.

Do you have any advice, idea, which could lead to improved efficiency?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.