Apple Script для выполнения команды терминала и отображения результатов
Я совершенно новичок со сценарием Apple (и сценариями в целом). У меня есть команда Terminal, которая использует cfgutil для отображения информации о большом количестве iPad.
Команда выглядит следующим образом:
./cfgutil -f --format JSON get-property name firmwareVersion batteryCurrentCapacity passcodeProtected configurationProfiles installedApps
cfgutil находится внутри приложения Apple Configurator 2
/Applications/Apple\\ Configurator\\ 2.app/Contents/MacOS/cfgutil
Я сделал Apple Script для генерации текстового файла из скрипта Python.
on run {input, parameters}
tell application "Terminal"
activate
do script with command "/Applications/Apple\\ Configurator\\ 2.app/Contents/MacOS/cfgutil -f --format JSON get-property name firmwareVersion batteryCurrentCapacity passcodeProtected configurationProfiles installedApps | python3 /Users/admin/Desktop/jsonpy3.py > /Users/admin/Desktop/Check.txt | top; exit"
end tell
end run
Скрипт Python (от thx до flaf):
#!/usr/bin/env python3
import sys
import json
human_readable_fields = {
'name': 'Nom',
'firmwareVersion': 'Firmware',
'batteryCurrentCapacity': 'Charge',
'passcodeProtected': 'Passcode',
'configurationProfiles': 'Profils',
'installedApps': 'Applications',
}
template = ' '.join(
['{name:<25.25}', # name will be truncated to 25 characters.
'{firmwareVersion:>10}',
'{batteryCurrentCapacity:>10}',
'{passcodeProtected:>15}',
'{configurationProfiles:>10}',
'{installedApps:>15}']
)
data = json.loads(''.join(sys.stdin.readlines()))
device_ids = data['Devices']
devices = []
for device_id in device_ids:
d = data['Output'][device_id]
device = {'id': device_id,
'name': d['name'],
'firmwareVersion': d['firmwareVersion'],
'batteryCurrentCapacity': d['batteryCurrentCapacity'],
'passcodeProtected': d['passcodeProtected'],
'configurationProfiles': len(d['configurationProfiles']),
'installedApps': len(d['installedApps'])}
devices.append(device)
# The header.
print(template.format(**human_readable_fields))
for device in devices:
if device['passcodeProtected']:
device['passcodeProtected'] = 'activé'
else:
device['passcodeProtected'] = 'désactivé'
# A device.
print(template.format(**device))
Но я бы предпочел только Apple Script, который отображает результаты во всплывающем окне. Есть хороший человек, чтобы помочь мне?:)