如何 enable/disable 为所有模拟器“显示为 运行 目的地”
How to enable/disable “Show as run destination” for all simulators
是否可以为多个 iOS 模拟器切换“Show as 运行 destination”标志,而不是在“ 设备和模拟器" window?
是否有用于该目的的命令行?
我决定自己用fswatch
找到它。顺便说一句,它对这种情况非常有用。通过在 切换 “Show as 运行 destination” 标志时监视文件的变化,我发现 Xcode正在更改 ~/Library/Preferences/com.apple.dt.Xcode.plist
文件
经过一些分析,我注意到我需要更改键以实现我的想法。关键是 DVTIgnoredDevices
并且它包含一组模拟器。因此,该列表中的每个模拟器 UUID 将在 Xcode.
中被忽略
现在,我可以使用 defaults
命令行工具更改 DVTIgnoredDevices
键,指定所需的值类型:
-array Allows the user to specify an array as the value for the given preference key:
defaults write somedomain preferenceKey -array element1 element2 element3
The specified array overwrites the value of the key if the key was present at the time of the write. If the key was not present, it is created with the new value.
示例:
defaults write com.apple.dt.Xcode DVTIgnoredDevices '(
"80E16DBC-2FE5-48AC-8A44-1F5DEFA00EA7",
"B8C4D5FF-8F1A-4895-BD16-CCAFECD71098"
)'
设置DVTIgnoredDevices
键后,需要清理DerivedData
文件夹并重启Xcode。要清理 DerivedData
文件夹,请参阅 答案或仅 运行 快捷方式 shift+alt+cmd+k
(我通常这样做)。
在 Xcode 版本 9.4 (9F1027a) 上测试。
更新:
我通常喜欢列表中只有几个模拟器,所以我决定使用 instruments -s devices
编写一个脚本并将所有当前模拟器添加到 DVTIgnoredDevices
键。然后我选择了要显示的模拟器
Xcode-全部隐藏-iPhone-simulators.sh
simulatorsIdentifiers=$(instruments -s devices |
grep -o "iPhone .* (.*) \[.*\]" | #only iPhone
grep -o "\[.*\]" | #only UUID
sed "s/^\[\(.*\)\]$//" | #remove square brackets
sed 's/^/"/;$!s/$/"/;$s/$/"/' | #add quotes
sed '$!s/$/,/' #add comma to separate each element
)
arrayOfSimulatorsIdentifiers=($(echo "$simulatorsIdentifiers" | tr ',' '\n'))
# Add simulators to DVTIgnoredDevices
echo "${#arrayOfSimulatorsIdentifiers[@]}"
for index in "${!arrayOfSimulatorsIdentifiers[@]}"
do
echo "$index Adding: ${arrayOfSimulatorsIdentifiers[index]}"
done
defaults write com.apple.dt.Xcode DVTIgnoredDevices -array ${arrayOfSimulatorsIdentifiers[@]}
是否可以为多个 iOS 模拟器切换“Show as 运行 destination”标志,而不是在“ 设备和模拟器" window? 是否有用于该目的的命令行?
我决定自己用fswatch
找到它。顺便说一句,它对这种情况非常有用。通过在 切换 “Show as 运行 destination” 标志时监视文件的变化,我发现 Xcode正在更改 ~/Library/Preferences/com.apple.dt.Xcode.plist
文件
经过一些分析,我注意到我需要更改键以实现我的想法。关键是 DVTIgnoredDevices
并且它包含一组模拟器。因此,该列表中的每个模拟器 UUID 将在 Xcode.
现在,我可以使用 defaults
命令行工具更改 DVTIgnoredDevices
键,指定所需的值类型:
-array Allows the user to specify an array as the value for the given preference key:
defaults write somedomain preferenceKey -array element1 element2 element3
The specified array overwrites the value of the key if the key was present at the time of the write. If the key was not present, it is created with the new value.
示例:
defaults write com.apple.dt.Xcode DVTIgnoredDevices '(
"80E16DBC-2FE5-48AC-8A44-1F5DEFA00EA7",
"B8C4D5FF-8F1A-4895-BD16-CCAFECD71098"
)'
设置DVTIgnoredDevices
键后,需要清理DerivedData
文件夹并重启Xcode。要清理 DerivedData
文件夹,请参阅 shift+alt+cmd+k
(我通常这样做)。
在 Xcode 版本 9.4 (9F1027a) 上测试。
更新:
我通常喜欢列表中只有几个模拟器,所以我决定使用 instruments -s devices
编写一个脚本并将所有当前模拟器添加到 DVTIgnoredDevices
键。然后我选择了要显示的模拟器
Xcode-全部隐藏-iPhone-simulators.sh
simulatorsIdentifiers=$(instruments -s devices |
grep -o "iPhone .* (.*) \[.*\]" | #only iPhone
grep -o "\[.*\]" | #only UUID
sed "s/^\[\(.*\)\]$//" | #remove square brackets
sed 's/^/"/;$!s/$/"/;$s/$/"/' | #add quotes
sed '$!s/$/,/' #add comma to separate each element
)
arrayOfSimulatorsIdentifiers=($(echo "$simulatorsIdentifiers" | tr ',' '\n'))
# Add simulators to DVTIgnoredDevices
echo "${#arrayOfSimulatorsIdentifiers[@]}"
for index in "${!arrayOfSimulatorsIdentifiers[@]}"
do
echo "$index Adding: ${arrayOfSimulatorsIdentifiers[index]}"
done
defaults write com.apple.dt.Xcode DVTIgnoredDevices -array ${arrayOfSimulatorsIdentifiers[@]}