on findLastTargetIndex(targetItem, itemList) set lastIndex to 0 repeat with i from (count of itemList) to 1 by -1 if item i of itemList is targetItem then set lastIndex to i exit repeat end if end repeat return lastIndex end findLastTargetIndex
do shell script "afplay /System/Library/Sounds/Pop.aiff"
tell application "System Settings" activate do shell script "afplay /System/Library/Sounds/Pop.aiff" delay 1 tell application "System Events" tell process "System Settings" -- 获取系统语言 set systemLanguage to do shell script "defaults read -g AppleLocale" if systemLanguage starts with "zh" then -- 简体中文系统 if systemLanguage is "zh_CN" then set menuItemName to "显示器" set menuBarItemName to "显示" set addButtonName to "添加" else -- 繁體中文系統 set menuItemName to "顯示器" set menuBarItemName to "顯示方式" set addButtonName to "加號" end if else if systemLanguage starts with "en" then -- SystemOfEnglishLanguage set menuItemName to "Displays" set menuBarItemName to "View" set addButtonName to "Add" -- else if systemLanguage starts with "**" then -- change ** to the Abbreviate of the LanguageYouUse -- set menuItemName to "..." -- change ... to the definition of "Displays" in the MacOS of the LanguageYouUse -- set emenuBarItemName to "??" -- change ?? to the definition of "View" in the MacOS of the LanguageYouUse -- set addButtonName to "$$" -- change $$ to the definition of "Add" in the MacOS of the LanguageYouUse end if click menu item menuItemName of menu menuBarItemName of menu bar item menuBarItemName of menu bar 1 delay 0.3 tell group 1 of group 2 of splitter group 1 of group 1 of window menuItemName try delay 1 -- 这里需要延迟,因为系统设置冷启动后不能立刻加载出右侧的界面 click pop up button addButtonName -- 获取所有菜单的名称 set menuItems to name of menu items of menu addButtonName of pop up button addButtonName -- 通过名字查找要准确一些,这里去找最后一个名字的索引,因为如果符合通用控制的调节,就会出现两个名字,一个是通用控制,一个是随航 set targetIndex to (my findLastTargetIndex("Levitate’s iPad", menuItems)) -- Need to Change the NameOfTheiPad in the QuotationMarks to Your ipad's -- 点击目标菜单项 delay 0.3 click menu item targetIndex of menu addButtonName of pop up button addButtonName do shell script "afplay /System/Library/Sounds/Blow.aiff" on error delay 0.5 do shell script "afplay /System/Library/Sounds/Hero.aiff" end try end tell end tell end tell end tell delay 1