Skip to content

Instantly share code, notes, and snippets.

@cdzombak
Created March 15, 2021 17:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdzombak/b93ce2c0dca0f53a0cbcc29784882dfd to your computer and use it in GitHub Desktop.
Save cdzombak/b93ce2c0dca0f53a0cbcc29784882dfd to your computer and use it in GitHub Desktop.
Add browser tab lists as Things tasks
-- RESET VALUES
set urlList to {}
set currentTab to 0
-- SET DATE STAMP
set the dateStamp to ((the current date) as string)
set noteTitle to "URL List from Chrome Tabs on " & the dateStamp
-- PROCESS TABS OF FRONTMOST CHROME WINDOW
tell application "Google Chrome.app"
set successCount to 0
set chromeWindow to the front window
set tabCount to (count of (every «class CrTb» of chromeWindow))
-- GET TAB INFORMATION
try
repeat with t in (every «class CrTb» of chromeWindow)
set currentTab to currentTab + 1
set tabTitle to (name of t)
set tabURL to («class URL » of t)
if currentTab is not equal to tabCount then
set tabInfo to (tabTitle & return & tabURL & return & return)
else
-- don't output double return on last tab
set tabInfo to (tabTitle & return & tabURL)
end if
--COPY TAB INFO TO END OF LIST
copy tabInfo to the end of urlList
--INCREMENT SUCCESS COUNT
set successCount to (successCount + 1)
end repeat
end try
end tell
-- MAKE INBOX ITEM IN THINGS
tell application id "com.culturedcode.ThingsMac"
make new to do with properties {name:(noteTitle), notes:urlList as text}
end tell
-- NOTIFY RESULTS
my notification_Center(successCount, tabCount)
-- NOTIFICATION CENTER
on notification_Center(successCount, itemNum)
set Plural_Test to (successCount) as number
if Plural_Test is -1 then
display notification "No Tabs Exported!" with title "Send Chrome Tabs to Things"
else if Plural_Test is 0 then
display notification "No Tabs Exported!" with title "Send Chrome Tabs to Things"
else if Plural_Test is equal to 1 then
display notification "Successfully exported " & itemNum & ¬
" tab to Things Inbox" with title "Send Chrome Tabs to Things"
else if Plural_Test is greater than 1 then
display notification "Successfully exported " & itemNum & ¬
" tabs to Things Inbox" with title "Send Chrome Tabs to Things"
end if
set itemNum to "0"
delay 1
end notification_Center
-- RESET VALUES
set urlList to {}
set currentTab to 0
-- SET DATE STAMP
set the dateStamp to ((the current date) as string)
set noteTitle to "URL List from Safari Tabs on " & the dateStamp
-- PROCESS TABS OF FRONTMOST SAFARI WINDOW
tell application "Safari"
set successCount to 0
set safariWindow to the front window
set tabCount to (count of (tabs of safariWindow))
-- GET TAB INFORMATION
try
repeat with t in (tabs of safariWindow)
set currentTab to currentTab + 1
set tabTitle to (name of t)
set tabURL to (URL of t)
if currentTab is not equal to tabCount then
set tabInfo to (tabTitle & return & tabURL & return & return)
else
-- don't output double return on last tab
set tabInfo to (tabTitle & return & tabURL)
end if
--COPY TAB INFO TO END OF LIST
copy tabInfo to the end of urlList
--INCREMENT SUCCESS COUNT
set successCount to (successCount + 1)
end repeat
end try
end tell
-- MAKE INBOX ITEM IN THINGS
tell application id "com.culturedcode.ThingsMac"
make new to do with properties {name:(noteTitle), notes:urlList as text}
end tell
-- NOTIFY RESULTS
my notification_Center(successCount, tabCount)
-- NOTIFICATION CENTER
on notification_Center(successCount, itemNum)
set Plural_Test to (successCount) as number
if Plural_Test is -1 then
display notification "No Tabs Exported!" with title "Send Safari Tabs to Things"
else if Plural_Test is 0 then
display notification "No Tabs Exported!" with title "Send Safari Tabs to Things"
else if Plural_Test is equal to 1 then
display notification "Successfully exported " & itemNum & ¬
" tab to Things Inbox" with title "Send Safari Tabs to Things"
else if Plural_Test is greater than 1 then
display notification "Successfully exported " & itemNum & ¬
" tabs to Things Inbox" with title "Send Safari Tabs to Things"
end if
set itemNum to "0"
delay 1
end notification_Center
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment