-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_safari_window_pos.applescript
49 lines (43 loc) · 1.57 KB
/
save_safari_window_pos.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
property numOfSafariWindows : 0
property posOfSafariWindows : {}
property sizeOfSafariWindows : {}
set theResults to display dialog "Restore window positions or save window positions?" buttons {"Restore", "Save"} default button "Restore" giving up after 5
log theResults
if (gave up of theResults) is true then
set the button returned of theResults to "Restore"
end if
if (button returned of theResults) is "Restore" then
tell application "Safari"
log {"numOfSafariWindows: " & numOfSafariWindows}
if (count of windows) < numOfSafariWindows then
repeat with i from (1 + (count of windows)) to numOfSafariWindows
make new document at the end of documents
end repeat
end if
end tell
tell application "System Events"
tell process "Safari"
repeat with i from 1 to numOfSafariWindows
set position of window i to (item i of posOfSafariWindows)
set size of window i to (item i of sizeOfSafariWindows)
end repeat
end tell
end tell
else
tell application "System Events"
tell process "Safari"
-- count of windows reflect the number of windows in the current desktop
-- if your current virtual desktop has no Safari windows, it will be zero
if (count of windows) > 0 then
set numOfSafariWindows to count of windows
set posOfSafariWindows to {}
set sizeOfSafariWindows to {}
repeat with i from 1 to numOfSafariWindows
set end of posOfSafariWindows to (position of window i)
set end of sizeOfSafariWindows to (size of window i)
end repeat
end if
log {"numOfSafariWindows: " & numOfSafariWindows}
end tell
end tell
end if