Skip to content

Instantly share code, notes, and snippets.

@troutcolor
Created October 21, 2023 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troutcolor/15a9831a0d0954cc3045956f2fc66d8d to your computer and use it in GitHub Desktop.
Save troutcolor/15a9831a0d0954cc3045956f2fc66d8d to your computer and use it in GitHub Desktop.
Make a montage of screenshots of the tabs open in Safari's top window
set URLs to windowOneTabs()
set mytempFolder to do shell script "mktemp -d "
set c to 0
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
click menu item "New Window" of menu "File" of menu bar 1
if menu item "Hide Favourites Bar" of menu "View" of menu bar 1 exists then
click menu item "Hide Favourites Bar" of menu "View" of menu bar 1
end if
end tell
keystroke "f" using {control down, command down}
end tell
tell application "Safari"
repeat with tURL in URLs
open location tURL
delay 5
tell application "System Events"
tell process "Safari"
keystroke "0" using {command down}
keystroke "+" using {command down}
keystroke "+" using {command down}
end tell
end tell
do shell script "screencapture -m " & mytempFolder & "/img" & (c) & ".png"
set c to c + 1
end repeat
do shell script "cd " & mytempFolder & ";/opt/homebrew/bin/montage -mode concatenate *.png out.jpg || exit 0 "
end tell
tell application "System Events"
tell process "Safari"
keystroke "f" using {control down, command down}
end tell
end tell
--just to see what is going on
do shell script "open " & mytempFolder
set resultFile to POSIX path of (choose file name with prompt "Save As File" default name "links-montage.jpg" default location path to desktop) as text
do shell script "mv " & mytempFolder & "/out.jpg " & quoted form of resultFile
on windowOneTabs()
tell application "Safari"
set tablist to tabs of window 1
set urlList to {}
repeat with currentTab in tablist
set currentURL to URL of currentTab
if currentURL is not missing value then
set end of urlList to currentURL as text
end if
end repeat
return urlList
end tell
end windowOneTabs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment