sesweitzer Posted August 15, 2016 Posted August 15, 2016 Greetings, I'm trying to find an Alfred 3 workflow that will allow me to close all the tabs to the left or to the right of the selected tab in Safari 9.1.2. I was using a Workflow called BrowserTabs but it seems to have quite working. Thanks, Steve
deanishe Posted August 15, 2016 Posted August 15, 2016 Put this in a Run Script Action with Language = /usr/bin/osascript (JS) // Close Safari tabs to the left of the active one. ObjC.import('stdlib') function run(argv) { var count = 0, safari = Application('Safari'), win = safari.windows[0], tabs = win.tabs, currentIdx = win.currentTab.index(); if (currentIdx == 1) { console.log('No tabs to close.') return } // start at currentIdx - 2 due to 0-indexing in JS for (i = currentIdx - 2; i >= 0; i--) { var tab = tabs[i]; tabs[i].close(); count++; } console.log(count + ' tab(s) closed'); } sesweitzer 1
deanishe Posted August 15, 2016 Posted August 15, 2016 (edited) And here's "Close Tabs to Right": // Close Safari tabs to the right of the active one. ObjC.import('stdlib') function run(argv) { var count = 0, safari = Application('Safari'), win = safari.windows[0], tabs = win.tabs, currentIdx = win.currentTab.index(); // console.log('Tab ' + currentIdx + '/' + tabs.length + ' active.'); if (currentIdx == tabs.length) { console.log('No tabs to close.') return } var first = tabs.length - 1, last = currentIdx; for (i = first; i >= last; i--) { // console.log('Closing tab ' + (i+1) + ' ...'); var tab = tabs[i]; tabs[i].close(); count++; } console.log(count + ' tab(s) closed'); } Edited May 13, 2021 by deanishe sesweitzer 1
sesweitzer Posted August 16, 2016 Author Posted August 16, 2016 Thanks deanishe! I just bought you a beer. I didn't totally understand your instructions because I've never created a workflow but you gave me enough and I got it working. Thanks for for the help and for getting me to the next level of using Alfred. It seems so simple now.
deanishe Posted August 16, 2016 Posted August 16, 2016 Thanks very much! I'll spend than on some of the lovely IPA the local beer shop has just started selling.
deanishe Posted August 16, 2016 Posted August 16, 2016 FWIW, I mostly use those Safari scripts (and others) with my AppScripts workflow. If you have a lot of scripts, it's maybe worth a look.
nycdude Posted May 13, 2021 Posted May 13, 2021 Hi, does this "Close tabs to the right" code still work in safari 14? Is there a workflow for this?
deanishe Posted May 13, 2021 Posted May 13, 2021 8 hours ago, nycdude said: Hi, does this "Close tabs to the right" code still work in safari 14? It appears to, yes. Why didn't you take two minutes to test it for yourself and find out?
nycdude Posted May 14, 2021 Posted May 14, 2021 (edited) I don't know how to test it. I'm not a developer or anything close to that; just a user of Alfred workflows, but I will find someone to test for me. Thanks! Edited May 14, 2021 by nycdude
TomBenz Posted July 3 Posted July 3 Is it possible to modify this to do similar things for Finder -- close left or right side tabs?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now