New Draft with Safari Tabs

Posted by agiletortoise, Last update about 4 years ago

Use AppleScript to gather all current tabs open in Safari and create a Markdown list in a new draft containing the title and URL of the pages in each tab.


  • runAppleScript

    on execute(draft)
    	set docText to ("## Safari Tabs" & linefeed as string) & linefeed as string
    	tell application "Safari"
    		set windowCount to number of windows
    		--Repeat for Every Window
    		repeat with x from 1 to windowCount
    			set tabcount to number of tabs in window x
    			--Repeat for Every Tab in Current Window
    			repeat with y from 1 to tabcount
    				--Get Tab Name & URL
    				set tabName to name of tab y of window x
    				set tabURL to URL of tab y of window x
    				set docText to docText & "- [" & tabName & "](" & tabURL & ")" & linefeed as string
    			end repeat
    		end repeat
    	end tell
    	return docText
    end execute
    --stub call to execute for easier testing in Script Editor
  • script

    let d = Draft.create();
    d.content = context.appleScriptResponses[0];


  • After Success Default , Tags: debug
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.