Skip to content

Instantly share code, notes, and snippets.

@mando
Last active July 22, 2020 18:06
Show Gist options
  • Save mando/a5bb9dfc2bd8f2ebd102c0228e70b0e7 to your computer and use it in GitHub Desktop.
Save mando/a5bb9dfc2bd8f2ebd102c0228e70b0e7 to your computer and use it in GitHub Desktop.
how to cleanup your Opera tabs from the CLI

how to cleanup your Opera tabs from the CLI

If you're like me, you have many, many tabs open. Sometimes, you might like to close all the stupid tabs you don't need, like those ding-dang leftover zoom tabs or all the jira tabs you opened in anger the night before.

This one kinda got away from me, not gonna lie.

Special thanks to https://gist.github.com/rentzsch/1047967 for the starting point

Examples

$ cleanup_opera
Usage: cleanup_opera URL_SUBSTRING_TO_FIND
$ cleanup_opera mlb
deleting tab "YETI Officially Licensed MLB™ Drinkware" with URL "https://www.yeti.com/en_US/mlb-drinkware.html"
$ cleanup_opera junk
No matching tabs
#!/bin/bash
if [ "$#" -ne 1 ]
then
echo "Usage: cleanup_opera URL_SUBSTRING_TO_FIND"
exit 1
fi
osascript cleanup_opera.scpt $1
on run argv
tell application "Opera"
# this returns a list of lists of matching tabs, one per window you have open
set listOfTabsInWindows to get every tab in every window whose URL contains item 1 of argv
# cheesy list merge don't functional me bro
set tabList to {}
repeat with t in listOfTabsInWindows
set tabList to tabList & t
end repeat
# let ya know if nothing matched your search (could do it earlier I suppose)
if items of tabList is {} then
log "No matching tabs"
return
end if
# close up them tabs with some cheesy logs
repeat with t in tabList
set tabTitle to (title of t as string)
set tabURL to (URL of t as string)
log "deleting tab \"" & tabTitle & "\" with URL \"" & tabURL & "\""
close t
end repeat
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment