« [NSTimeZone]基本 | トップページ | [AppleScript]選択中のファイル名のフォルダを作ってファイルをその中に入れる »

[mobileconfig] timeZone

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSData : a reference to refMe's NSData
property refNSURL : a reference to refMe's NSURL
property refNSDate : a reference to refMe's NSDate
property refNSDateFormatter : a reference to NSDateFormatter
property refNSMutableArray : a reference to refMe's NSMutableArray
property refNSMutableDictionary : a reference to refMe's NSMutableDictionary
property refNSPropertyListSerialization : a reference to refMe's NSPropertyListSerialization

set strPayloadType to "com.apple.time" as text
set strPayloadDisplayName to "com.apple.time" as text
set strPayloadOrganization to "com.cocolog-nifty.quicktimer" as text
set strPayloadDescription to "時間関連の設定です" as text
set strConsentTextDefault to "日本語の詳しい解説例:この設定は削除しないでください
日時に関する設定です" as text
set strConsentTextEn to "Do not remove this setting" as text

set numTargetDeviceType to 5 as number
(*
0 = Any/unspecified
1 = iPhone/iPad/iPod Touch
2 = Apple Watch
3 = HomePod
4 = Apple TV
5 = Mac
*)

########################
####出力ファイル関連
set strRelativePath to ("~/Desktop/") as text
set ocidRelativePath to refNSString's stringWithString:strRelativePath
set ocidFullPath to ocidRelativePath's stringByStandardizingPath()
set ocidFullPathURL to refMe's NSURL's fileURLWithPath:ocidFullPath
set aliasFullPathURL to ocidFullPathURL as alias

set strFileName to ("" & strPayloadDisplayName & ".mobileconfig") as text
##set strFileName to ("" & strPayloadDisplayName & ".plist") as text
set recordConsentText to {default:strConsentTextDefault, jp:strConsentTextDefault} as record
#set recordConsentText to {default:strConsentTextDefault, jp:strConsentTextDefault, en:strConsentTextEn} as record
######
set aliasSaveFilePath to choose file name with prompt "ファイル名を付けてください" default name strFileName default location (aliasFullPathURL)
set strSaveFilePath to POSIX path of aliasSaveFilePath as text
###NSStringにして
set ocidPosixPath to refNSString's stringWithString:strSaveFilePath
##NSStringフルパス
set ocidPosixFullPath to ocidPosixPath's stringByStandardizingPath

########################
#######共通項目
set numPayloadVersion to (doGetDateNo("yyyyMMdd")) as number

########################
#######PayloadContentDict com.apple.timezone.auto
set ocidPayloadContentTimeServer to refNSMutableDictionary's alloc()'s initWithCapacity:0
set strPayloadUUID to doUUIDgen() as text
set strPayloadIdentifier to ("com.apple.timezone.auto." & strPayloadUUID & "") as text
tell ocidPayloadContentTimeServer

ocidPayloadContentTimeServer's setObject:("Asia/Tokyo" as text) forKey:"timeZone"
##ocidPayloadContentTimeServer's setObject:("/usr/share/zoneinfo/Asia/Tokyo" as text) forKey:"timeZone"
ocidPayloadContentTimeServer's setObject:("ntp.nict.jp" as text) forKey:"timeServer"

ocidPayloadContentTimeServer's setObject:"com.apple.MCX" forKey:"PayloadDisplayName"
ocidPayloadContentTimeServer's setObject:"com.apple.MCX" forKey:"PayloadDescription"
ocidPayloadContentTimeServer's setObject:(strPayloadUUID as text) forKey:"PayloadUUID"
ocidPayloadContentTimeServer's setObject:(strPayloadIdentifier as text) forKey:"PayloadIdentifier"
ocidPayloadContentTimeServer's setObject:(strPayloadOrganization as text) forKey:"PayloadOrganization"
ocidPayloadContentTimeServer's setObject:("com.apple.MCX" as text) forKey:"PayloadType"
ocidPayloadContentTimeServer's setObject:(numPayloadVersion as number) forKey:"PayloadVersion"

end tell


########################
#######PayloadContentDict com.apple.timezone.auto
set ocidPayloadContentMain to refNSMutableDictionary's alloc()'s initWithCapacity:0
set strPayloadUUID to doUUIDgen() as text

set strPayloadIdentifier to ("com.apple.timezone.auto." & strPayloadUUID & "") as text
tell ocidPayloadContentMain

ocidPayloadContentMain's setObject:(true as boolean) forKey:"Active"

ocidPayloadContentMain's setObject:"com.apple.timezone.auto" forKey:"PayloadDisplayName"
ocidPayloadContentMain's setObject:"com.apple.timezone.auto" forKey:"PayloadDescription"
ocidPayloadContentMain's setObject:(strPayloadUUID as text) forKey:"PayloadUUID"
ocidPayloadContentMain's setObject:(strPayloadIdentifier as text) forKey:"PayloadIdentifier"
ocidPayloadContentMain's setObject:(strPayloadOrganization as text) forKey:"PayloadOrganization"
ocidPayloadContentMain's setObject:("com.apple.timezone.auto" as text) forKey:"PayloadType"
ocidPayloadContentMain's setObject:(numPayloadVersion as number) forKey:"PayloadVersion"

end tell

########################
#######PayloadContentArray
set strPayloadUUID to doUUIDgen() as text
set strPayloadIdentifier to ("" & strPayloadDisplayName & "." & strPayloadUUID & "") as text
set ocidPayloadContentArray to refNSMutableArray's alloc()'s initWithCapacity:0
tell ocidPayloadContentArray
ocidPayloadContentArray's addObject:ocidPayloadContentMain
ocidPayloadContentArray's addObject:ocidPayloadContentTimeServer
end tell

########################
#######ROOT Dict
set strPayloadUUID to doUUIDgen() as text
set strPayloadIdentifier to ("" & strPayloadDisplayName & "." & strPayloadUUID & "") as text
set ocidPlistData to refNSMutableDictionary's alloc()'s initWithCapacity:0
tell ocidPlistData
#####PayloadContentはここにArrayで挿入
ocidPlistData's setObject:ocidPayloadContentArray forKey:"PayloadContent"
#####
ocidPlistData's setObject:strPayloadDisplayName forKey:"PayloadDisplayName"
ocidPlistData's setObject:strPayloadDescription forKey:"PayloadDescription"
ocidPlistData's setObject:recordConsentText forKey:"ConsentText"
ocidPlistData's setObject:(strPayloadUUID as text) forKey:"PayloadUUID"
ocidPlistData's setObject:(strPayloadIdentifier as text) forKey:"PayloadIdentifier"
ocidPlistData's setObject:(strPayloadOrganization as text) forKey:"PayloadOrganization"
ocidPlistData's setObject:"Configuration" forKey:"PayloadType"
ocidPlistData's setObject:"System" forKey:"PayloadScope"
ocidPlistData's setObject:(numTargetDeviceType as number) forKey:"TargetDeviceType"
ocidPlistData's setObject:(false as boolean) forKey:"PayloadRemovalDisallowed"
#ocidPlistData's setObject:(false as boolean) forKey:"HasRemovalPasscode"
#ocidPlistData's setObject:(false as boolean) forKey:"IsEncrypted"
ocidPlistData's setObject:(numPayloadVersion as number) forKey:"PayloadVersion"
end tell


######################
###定型どちらか選ぶ
###バイナリー形式
set ocidBinplist to refMe's NSPropertyListBinaryFormat_v1_0
###XML形式
set ocidXmlplist to refMe's NSPropertyListXMLFormat_v1_0
####書き込み用にバイナリーデータに変換
set ocidPlistEditData to refMe's NSPropertyListSerialization's dataWithPropertyList:ocidPlistData format:ocidXmlplist options:0 |error|:(missing value)
####書き込み
####ocidPlistEditData's writeToFile:ocidPosixFullPath atomically:true
set boolWritetoUrlArray to ocidPlistEditData's writeToFile:ocidPosixFullPath options:0 |error|:(reference)
set ocidWriteToUrlResults to item 1 of boolWritetoUrlArray
set ocidErrorResults to item 2 of boolWritetoUrlArray
if ocidWriteToUrlResults is true then
ocidPlistEditData's release()
ocidPlistData's release()
else
try
log ocidWriteToUrlResults's localizedDescription() as text
log ocidWriteToUrlResults's localizedFailureReason() as text
log ocidWriteToUrlResults's localizedRecoverySuggestion() as text
log ocidWriteToUrlResults's localizedRecoveryOptions() as text
log ocidWriteToUrlResults's recoveryAttempter() as text
log ocidWriteToUrlResults's helpAnchor() as text
end try
log "ファイルの書き込みに失敗しました"
end if

-->テキスト形式のUUIDを返します
to doUUIDgen()
set ocidConcreteUUID to refMe's NSUUID's UUID()
set ocidUUIDString to ocidConcreteUUID's UUIDString()
set strUUIDString to ocidUUIDString as text
return strUUIDString
end doUUIDgen

to doGetDateNo(strDateFormat)
####日付情報の取得
set ocidDate to refNSDate's |date|()
###日付のフォーマットを定義
set ocidNSDateFormatter to refNSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(refMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidNSDateFormatter's setDateFormat:strDateFormat
set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

    <dict>

        <key>PayloadContent</key>

        <array>

            <dict>

                <key>Active</key>

                <false />

                <key>PayloadDescription</key>

                <string>com.apple.timezone.auto</string>

                <key>PayloadDisplayName</key>

                <string>com.apple.timezone.auto</string>

                <key>PayloadIdentifier</key>

                <string>com.apple.timezone.auto.DA691BE5-AA75-44FB-9E80-F32AE521102D</string>

                <key>PayloadOrganization</key>

                <string>com.cocolog-nifty.quicktimer</string>

                <key>PayloadType</key>

                <string>com.apple.timezone.auto</string>

                <key>PayloadUUID</key>

                <string>DA691BE5-AA75-44FB-9E80-F32AE521102D</string>

                <key>PayloadVersion</key>

                <integer>20221002</integer>

            </dict>

            <dict>

                <key>PayloadDescription</key>

                <string>com.apple.MCX</string>

                <key>PayloadDisplayName</key>

                <string>com.apple.MCX</string>

                <key>PayloadIdentifier</key>

                <string>com.apple.timezone.auto.B153EFBB-7F02-41F1-A2A0-DB96E7A27319</string>

                <key>PayloadOrganization</key>

                <string>com.cocolog-nifty.quicktimer</string>

                <key>PayloadType</key>

                <string>com.apple.MCX</string>

                <key>PayloadUUID</key>

                <string>B153EFBB-7F02-41F1-A2A0-DB96E7A27319</string>

                <key>PayloadVersion</key>

                <integer>20221002</integer>

                <key>timeServer</key>

                <string>ntp.nict.jp</string>

                <key>timeZone</key>

                <string>Asia/Tokyo</string>

            </dict>

        </array>

        <key>ConsentText</key>

        <dict>

            <key>default</key>

            <string>日本語の詳しい解説例:この設定は削除しないでください

日時に関する設定です</string>

            <key>jp</key>

            <string>日本語の詳しい解説例:この設定は削除しないでください

日時に関する設定です</string>

        </dict>

        <key>PayloadDescription</key>

        <string>時間関連の設定です</string>

        <key>PayloadDisplayName</key>

        <string>com.apple.time</string>

        <key>PayloadIdentifier</key>

        <string>com.apple.time.C7D93B29-0E2C-49A1-BB88-C6685051B81E</string>

        <key>PayloadOrganization</key>

        <string>com.cocolog-nifty.quicktimer</string>

        <key>PayloadRemovalDisallowed</key>

        <false />

        <key>PayloadScope</key>

        <string>System</string>

        <key>PayloadType</key>

        <string>Configuration</string>

        <key>PayloadUUID</key>

        <string>C7D93B29-0E2C-49A1-BB88-C6685051B81E</string>

        <key>PayloadVersion</key>

        <integer>20221002</integer>

        <key>TargetDeviceType</key>

        <integer>5</integer>

    </dict>

</plist>

|

« [NSTimeZone]基本 | トップページ | [AppleScript]選択中のファイル名のフォルダを作ってファイルをその中に入れる »

Admin Mobileconfig」カテゴリの記事

Admin Device Management」カテゴリの記事