applescript:使用 Finder 移动文件时避免声音
applescript: avoid sound when using Finder to move files
我正在尝试用 Applescript 处理一些文件。这包括移动
每个文件到一个工作目录进行处理
当我的脚本执行时
tell application "Finder"
move file to workdir
end tell
它总是会发出声音(就像使用 finder GUI dos 移动文件一样)
我怎样才能防止这种情况发生?该脚本可能会 运行 好几个小时,并且此脚本不断发出的声音会令人不安。我无法完全关闭声音,因为其他事情可能需要提醒我
由于您在 OP 中明确说明 "I cannot turn sound off completely as other things may need to alert me",我建议您使用 move
命令 来自 System Events 的磁盘文件夹文件套件,因为使用此方法它不会发出任何声音。
move v : Move disk item(s) to a new location.
move disk item : The disk item(s) to be moved.
to location specifier : The new location for the disk item(s).
→ disk item
示例:
set thisItem to "/path/to/disk item"
set thisFolder to "/path/to/folder"
tell application "System Events"
move disk item thisItem to thisFolder
end tell
您可以通过名为 "Volume Mount.aif" 的系统文件禁用声音。一种非破坏性的方法是将文件移动到另一个位置。移动文件需要根权限。
要执行此命令,您还需要禁用系统完整性保护:
https://developer.apple.com/library/content/documentation/Security/Conceptual/System_Integrity_Protection_Guide/ConfiguringSystemIntegrityProtection/ConfiguringSystemIntegrityProtection.html
您可以通过在终端中输入以下命令来移动它:
sudo mv /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/Volume\ Mount.aif ~/Desktop/
要将其移回:
sudo mv ~/Desktop/Volume\ Mount.aif /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/
需要重新启动才能再次播放声音。
我正在尝试用 Applescript 处理一些文件。这包括移动 每个文件到一个工作目录进行处理
当我的脚本执行时
tell application "Finder"
move file to workdir
end tell
它总是会发出声音(就像使用 finder GUI dos 移动文件一样) 我怎样才能防止这种情况发生?该脚本可能会 运行 好几个小时,并且此脚本不断发出的声音会令人不安。我无法完全关闭声音,因为其他事情可能需要提醒我
由于您在 OP 中明确说明 "I cannot turn sound off completely as other things may need to alert me",我建议您使用 move
命令 来自 System Events 的磁盘文件夹文件套件,因为使用此方法它不会发出任何声音。
move v : Move disk item(s) to a new location.
move disk item : The disk item(s) to be moved.
to location specifier : The new location for the disk item(s).
→ disk item
示例:
set thisItem to "/path/to/disk item"
set thisFolder to "/path/to/folder"
tell application "System Events"
move disk item thisItem to thisFolder
end tell
您可以通过名为 "Volume Mount.aif" 的系统文件禁用声音。一种非破坏性的方法是将文件移动到另一个位置。移动文件需要根权限。
要执行此命令,您还需要禁用系统完整性保护: https://developer.apple.com/library/content/documentation/Security/Conceptual/System_Integrity_Protection_Guide/ConfiguringSystemIntegrityProtection/ConfiguringSystemIntegrityProtection.html
您可以通过在终端中输入以下命令来移动它:
sudo mv /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/Volume\ Mount.aif ~/Desktop/
要将其移回:
sudo mv ~/Desktop/Volume\ Mount.aif /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/
需要重新启动才能再次播放声音。