property finalCode : false
my activateGUIscripting()
# Trigger Clear Recent Items from Apple menu
if finalCode then
my selectSubMenu("Finder", 1, 9, -1)
else
my select_SubMenu("Finder", 1, 9, -1)
end if
# Trigger Clear Recent Folders from Go To menu
if finalCode then
# my selectSubMenu("Finder", 6, -3, -1)
else
my select_SubMenu("Finder", 6, -3, -1)
end if
#=====
on activateGUIscripting()
(* to be sure than GUI scripting will be active *)
tell application "System Events"
if not (UI elements enabled) then set (UI elements enabled) to true
end tell
end activateGUIscripting
#=====
(*
==== Uses GUIscripting ====
*)
on selectSubMenu(theApp, mt, mi, ms)
activate application theApp
tell application "System Events" to tell application process theApp to tell menu bar 1 to ¬
tell menu bar item mt to tell menu 1 to tell menu item mi to tell menu 1 to click menu item ms
end selectSubMenu
#=====
(*
==== Uses GUIscripting ====
*)
on select_SubMenu(theApp, mt, mi, ms)
activate application theApp
tell application "System Events" to tell process theApp to tell menu bar 1
get name of menu bar items
(*{
01 - "Apple",
02 - "Finder",
03 - "Fichier",
04 - "Édition",
05 - "Présentation",
06 - "Aller",
07 - "Fenêtre",
08 - "Aide"}
*)
get name of menu bar item mt
-- {"Apple"}
tell menu bar item mt to tell menu 1
get name of menu items
(* {01 - "À propos de ce Mac",
02 - "Informations système…",
03 - "Mise à jour de logiciels…",
04 - "App Store…",
05 - missing value,
06 - "Préférences Système…",
07 - "Dock",
08 - missing value,
09 - "Éléments récents"
10 - missing value,
11 - "Forcer à quitter…",
12 - "Forcer à quitter Finder",
13 - missing value,
14 - "Suspendre l’activité",
15 - "Redémarrer…",
16 - "Redémarrer",
17 - "Éteindre…",
18 - "Éteindre",
19 - missing value,
20 - "Fermer la session WXYZ…",
21 - "Fermer la session WXY"}
*)
get name of menu item mi
--"Éléments récents"
tell menu item mi to tell menu 1
get name of menu items
(* {
1 - "Applications",
2 -
-2 - missing value,
-1 - "Effacer le menu"}
*)
get name of menu item ms
-- "Effacer le menu"
--click menu item ms
end tell -- menu item…
end tell -- menu bar…
end tell -- System Events
end select_SubMenu
#=====