2014-10-01 61 views
1

我想用蘋果腳本來禁用隱私瀏覽檢查隱私瀏覽菜單項在Safari中的AppleScript檢查

之前,我跑禁用代碼我想確保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 

問題是,如果我運行這個腳本和私人瀏覽未激活它將acti vate私人模式。

所以我想,如果私人模式被激活。所以才把我會打電話給上述蘋果腳本

感謝

回答

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或液滴)的前景:利用這個腳本可以在包的的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" 
+0

一個簡單的問題:每當腳本運行的應用程序。應用程序來到前臺.i.e當我在Safari瀏覽器上瀏覽和這個腳本是由我的應用程序運行Safari瀏覽器去背景和應用程序來到前臺。我不希望我的應用程序來到前臺 – 2014-10-08 13:21:10

+0

我編輯了我的答案。 – jackjr300 2014-10-08 20:21:17

+0

這不是我的問題。我不想讓應用程序運行背景。我每隔15秒就從應用程序定時器調用這個腳本。當我在safari中瀏覽時,腳本被稱爲我的應用程序出現在前面,所以我需要每次點擊safari圖標返回到safari – 2014-10-13 10:51:25

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 

我沒有一個英文系統在這裏,也許有這樣的標題開啓你的系統,也?

邁克爾/漢堡