我想使用Apple脚本禁用隐私浏览
在我运行禁用代码之前,我想确保 PrivateMode 启用
禁用我使用以下苹果脚本
tell application "System Events"
tell process "Safari"
click menu item "Private Browsing" of menu 1 of menu bar item "Safari" of menu bar 1
end tell
end tell
问题是,如果我运行此脚本并且未激活私人浏览,则会激活私人模式。
所以我希望检查检测私有模式是否已启用。所以我才会调用上面的苹果脚本
由于
答案 0 :(得分:1)
使用" AXMenuItemMarkChar "用于检查菜单项的属性。
tell application "System Events"
tell process "Safari"
tell menu item "Private Browsing" of menu 1 of menu bar item "Safari" of menu bar 1
if value of attribute "AXMenuItemMarkChar" is "✓" then click -- disabling
end tell
end tell
end tell
更新:
不要将应用程序(AppleScript小程序或Droplet)打开到前台:使用此脚本在软件包(小程序)的 Info.plist 中添加属性LSBackgroundOnly
。
set tApp to choose file with prompt "Select your application (applet AppleScript)"
set tPlist to quoted form of ((POSIX path of tApp) & "Contents/Info")
do shell script "/usr/bin/defaults write " & tPlist & " LSBackgroundOnly -bool TRUE"
do shell script "/usr/bin/defaults write " & tPlist & " LSUIElement -bool TRUE"
答案 1 :(得分:1)
有趣的事实: 在德国系统上运行Safari,菜单项标题“私人浏览...”切换到“私人浏览”(没有三点)。使用相同的处理程序
无法打开和关闭私人浏览tell application "System Events"
tell process "Safari"
try
-- turn Private Browsing on
click menu item "Privates Surfen …" of menu 1 of menu bar item "Safari" of menu bar 1
-- turn Private Browsing off
click menu item "Privates Surfen" of menu 1 of menu bar item "Safari" of menu bar 1
end try
end tell
end tell
我这里没有英文系统,也许你的系统上也有这样的标题开关?
迈克尔/汉堡