Created
June 27, 2020 17:11
-
-
Save bcks/5e2ab6ed47362efe9cdcc2f160aabcd5 to your computer and use it in GitHub Desktop.
Use AppleScript to export all open Safari Tabs into a BBEdit list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Make a BBEdit list of all open Safari tabs | |
Adapted by John Emerson, https://backspace.com | |
from Jesse Squires, https://www.jessesquires.com | |
who adapted it from http://veritrope.com/code/safari-tab-list-to-omnifocus/ | |
*) | |
global allItems | |
set allItems to {} | |
global successCount | |
set successCount to 0 | |
tell application "BBEdit" | |
make new text window | |
end tell -- application "BBEdit" | |
my processSafariTabsInFrontmostWindow() | |
my exportAllItemsToBBEdit(allItems) | |
my postResultsToNotificationCenter(successCount) | |
log "Complete!" | |
(* | |
====== | |
Functions | |
====== | |
*) | |
on processSafariTabsInFrontmostWindow() | |
tell application "Safari" | |
set currentTab to 0 | |
set safariWindow to the front window | |
set tabCount to (count of (tabs of safariWindow)) | |
log "Processing " & tabCount & " Safari tabs..." | |
try | |
repeat with eachTab in (tabs of safariWindow) | |
set currentTab to currentTab + 1 | |
set tabItem to {tabTitle:(name of eachTab), tabURL:(URL of eachTab)} | |
copy tabItem to the end of allItems | |
set successCount to (successCount + 1) | |
end repeat | |
end try | |
end tell | |
end processSafariTabsInFrontmostWindow | |
on exportAllItemsToBBEdit(allItems) | |
repeat with eachItem in allItems | |
createBBEditInboxItem(tabTitle of eachItem, tabURL of eachItem) | |
end repeat | |
end exportAllItemsToBBEdit | |
on createBBEditInboxItem(tabTitle, tabURL) | |
tell front document of application "Script Editor" | |
log "Creating inbox item for tab: " & tabTitle | |
end tell | |
tell application "BBEdit" | |
tell text window 1 | |
select insertion point after (last character) | |
set selection to (((tabTitle as string) & " " & tabURL as string) & " | |
") | |
end tell | |
end tell | |
end createBBEditInboxItem | |
on postResultsToNotificationCenter(successCount as number) | |
log "Posting notification..." | |
set notifTitle to "Send Safari Tabs to BBEdit Inbox" | |
set notifMessage to "" | |
if successCount is less than or equal to 0 then | |
set notifMessage to "No Tabs Exported!" | |
else | |
set notifMessage to "Successfully exported " & successCount & " tabs" | |
end if | |
display notification notifMessage with title notifTitle | |
end postResultsToNotificationCenter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment