Skip to content

Commit de816e0

Browse files
authored
Update automated-notebook-run-script.py
1 parent b26b159 commit de816e0

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

scripts/automated-notebook-run-script.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -190,27 +190,42 @@ def main():
190190
""",
191191
download_button,
192192
)
193-
applescript = """
193+
applescript = r'''
194+
set buttonInfo to {}
195+
194196
tell application "System Events"
195-
tell process "Safari"
196-
set buttonInfo to {}
197-
repeat with aButton in (every button of window 1)
198-
set theName to name of aButton
199-
if theName is missing value then
200-
set theName to description of aButton
201-
end if
202-
if theName is missing value then
203-
set theName to role description of aButton
204-
end if
205-
if theName is missing value then
206-
set theName to "«no name»"
207-
end if
208-
set end of buttonInfo to theName
209-
end repeat
210-
return buttonInfo
211-
end tell
197+
repeat with proc in (every process whose background only is false)
198+
set procName to name of proc
199+
try
200+
repeat with w in windows of proc
201+
repeat with b in (buttons of w)
202+
set bName to ""
203+
try
204+
set bName to name of b
205+
end try
206+
if bName is missing value or bName = "" then
207+
try
208+
set bName to description of b
209+
end try
210+
end if
211+
if bName is missing value or bName = "" then
212+
try
213+
set bName to role description of b
214+
end try
215+
end if
216+
if bName is missing value or bName = "" then
217+
set bName to "«no name»"
218+
end if
219+
220+
set end of buttonInfo to procName & " — " & bName
221+
end repeat
222+
end repeat
223+
end try
224+
end repeat
212225
end tell
213-
"""
226+
227+
return buttonInfo
228+
'''
214229

215230
result = subprocess.run(["osascript", "-e", applescript], capture_output=True, text=True)
216231
print(result.stdout)

0 commit comments

Comments
 (0)