从终端或AppleScript运行命令时的不同结果
当我在终端中运行从终端或AppleScript运行命令时的不同结果,applescript,Applescript,当我在终端中运行默认值读取'com.apple.Safari'时,我得到了大量信息,特别是我感兴趣的值:默认值读取'com.apple.Safari'“NSWindowFrame BrowserWindowFrame' 但在AppleScript中运行时,结果完全不同: do shell script "defaults read 'com.apple.Safari'" (* { ResetCloudHistory = 1; cloudBookmarksMig
默认值读取'com.apple.Safari'
时,我得到了大量信息,特别是我感兴趣的值:默认值读取'com.apple.Safari'“NSWindowFrame BrowserWindowFrame'
但在AppleScript中运行时,结果完全不同:
do shell script "defaults read 'com.apple.Safari'"
(*
{
ResetCloudHistory = 1;
cloudBookmarksMigrationEligibilityDataInvalidated = 1;
}
*)
因此,当我运行AppleScript询问我感兴趣的密钥时,我会收到错误消息:
The domain/default pair of (com.apple.Safari, NSWindow Frame BrowserWindowFrame) does not exist
我想这是出于安全考虑
有人知道我可以用什么方法让applescript访问此设置并在以后写入它吗
注意:使用Mac OS 10.14 Mojave从脚本编辑器中读取macOS Mojave中的沙盒版本com.apple.Safari.plist,您需要将脚本编辑器添加到:系统首选项安全和隐私隐私完整磁盘访问
然后:
返回,例如:
"88 73 1264 804 0 0 1440 877 "
请注意,如果通过其他方法运行do shell脚本
命令,则需要将该方法中涉及的应用程序添加到:系统首选项安全和隐私隐私完整磁盘访问
在macOS Mojave中,要查看不同之处,请参见终端:
$ defaults read ~/Library/Preferences/com.apple.Safari.plist
{
IncludeDevelopMenu = 1;
WebKitDeveloperExtrasEnabledPreferenceKey = 1;
"WebKitPreferences.developerExtrasEnabled" = 1;
}
$
$ defaults read ~/Library/Containers/com.apple.Safari/Data/Library/Preferences/com.apple.Safari.plist 'NSWindow Frame BrowserWindowFrame'
88 73 1264 804 0 0 1440 877
$
但是,后面使用do shell脚本的相同命令
命令:
根据返回的内容,它显然正在访问沙盒版本的com.apple.Safari.plist。在Sierra上,我使用这两种方法都得到了相同的输出(除了由applescript生成的行尾是CR)。我问钥匙时得到了相同的结果。请包括您正在运行的操作系统,因为它是applescript所涉及的许多更改的来源。在macOS Catalina中使用脚本编辑器进行测试时,对于那些
默认
命令,我在脚本编辑器和终端之间获得了相同的输出。您使用的是什么版本的macOS?更新如上:使用10.14 Mojave
$ defaults read ~/Library/Preferences/com.apple.Safari.plist
{
IncludeDevelopMenu = 1;
WebKitDeveloperExtrasEnabledPreferenceKey = 1;
"WebKitPreferences.developerExtrasEnabled" = 1;
}
$
$ defaults read ~/Library/Containers/com.apple.Safari/Data/Library/Preferences/com.apple.Safari.plist 'NSWindow Frame BrowserWindowFrame'
88 73 1264 804 0 0 1440 877
$
do shell script "defaults read 'com.apple.Safari' 'NSWindow Frame BrowserWindowFrame'"