Hi All.
I was trying to find a good approach to extract static text from Notification Centre.
So my first try was to use GUI Scripting. The code below does the job…
But I was thinking wouldn’t this be possible with ASObjC.
Anyone knowing anything about this ??.
tell application "System Events" to tell process "SystemUIServer"
tell menu bar 1
class of UI elements
get its name of UI elements
end tell
activate
click menu bar item "Notification Centre" of menu bar 1
end tell
tell application "System Events" to tell process "Notification Centre"
tell window 1
--> {radio group, scroll area, button}
tell radio group 1
--> {radio button, radio button}
end tell
tell scroll area 1
--> {table, scroll bar}
tell table 1
tell UI element of every row
tell every static text
set uiText to get its name
-- Get the static text of Notification Centre.
return item 1 of item 4 of uiText
end tell
end tell
end tell
tell scroll bar 1
--> {value indicator, button, button, button, button}
tell value indicator 1
set value to 0
end tell
end tell
end tell
tell buttons
if ((get its description) is {"Notification Centre Preferences"} as list) then
-- click item 1
else
error "Script got an error: User canceled." number -128
end if
end tell
end tell
end tell
No. Developers have very little access to the notification center, which is a separate process.
Hi Shane.
I thought that was the case, here is my code at least use GUI Scripting.
tell application "System Events" to tell process "SystemUIServer"
set frontmost to true
click menu bar item "Notification Centre" of menu bar 1
end tell
set theNotification to getNotificationText(4)
set {theTitle, theTime, theSubtitle, missing value, theMessage} to theNotification
on getNotificationText(rowNumber)
tell application "System Events" to tell process "Notification Centre"
tell window 1 to tell scroll area 1 to tell table 1
tell UI element of every row
tell every static text
set rowText to get its name
-- Get the static text of Notification Centre.
return item 1 of item rowNumber of rowText
end tell
end tell
end tell
end tell
end getNotificationText
tell application "System Events" to tell process "SystemUIServer"
set frontmost to true
click menu bar item "Notification Centre" of menu bar 1
end tell
This one include error handler, the 2 first index are not used…
So the first message will always be index 3.
tell application "System Events" to tell process "SystemUIServer"
set frontmost to true
click menu bar item "Notification Centre" of menu bar 1
end tell
set theNotification to getNotificationText(6)
set {theTitle, theTime, theSubtitle, missing value, theMessage} to theNotification
its theTitle & " " & theTime & " " & theSubtitle & " " & theMessage
on getNotificationText(rowNumber)
tell application "System Events" to tell process "Notification Centre"
tell window 1 to tell scroll area 1 to tell table 1
tell UI element of every row
tell every static text
set rowText to get its name
-- Get the static text of Notification Centre.
if (count items of item 1 of item rowNumber of rowText) > 4 then
return item 1 of item rowNumber of rowText
else
display dialog "This row index doesn't contain any message"
error "missing value" number -128
end if
end tell
end tell
end tell
end tell
end getNotificationText
Some events is predefined by the Cocoa. So, you can trap predefined events using ASObjC. Now I don’t remember where I met a list of these events. See NSNotification.Name documentation.