I was able to unminimize all the windows in their respective desktops with the following code
tell application "Safari"
try
set miniaturized of windows to false
end try
end tell
Then I use your code mixed with other bits I found online.
I have 4 tabs pinned so the first tab a new window opens is index = 5
The code checks to see if a window is active and opens a new tab.
if there is no window, opens a new window, which comes with a tab I want to get rid of and opens a new tab with raindrop (tab manager)
to finish, it does cmd+l to focus on the url bar.
this is the full code
tell application "Safari"
try
set miniaturized of windows to false
end try
end tell
on count_windows_on_current_space(process_name)
tell application "System Events"
tell process process_name
return count of windows
end tell
end tell
end count_windows_on_current_space
if application "Safari" is running then
tell application "Safari"
if my count_windows_on_current_space("Safari") = 0 then
make new document
open location "https://app.raindrop.io/"
activate
tell window 1
close (tabs where index = 5)
end tell
delay 1
tell application "System Events" to keystroke "l" using command down
else
open location "https://app.raindrop.io/"
activate
delay 1
tell application "System Events" to keystroke "l" using command down
end if
end tell
else
tell application "Safari"
activate
open location "https://app.raindrop.io/"
delay 1
tell application "System Events" to keystroke "l" using command down
end tell
end if