001 | #! /usr/bin/env osascript |
---|
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
003 | # |
---|
004 | # フォントを提供する場合用の |
---|
005 | # モバイルコンフィグを提供します |
---|
006 | # 使用期限を設定します |
---|
007 | # com.cocolog-nifty.quicktimer.icefloe |
---|
008 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
009 | use AppleScript version "2.8" |
---|
010 | use framework "Foundation" |
---|
011 | use framework "UniformTypeIdentifiers" |
---|
012 | use framework "AppKit" |
---|
013 | use scripting additions |
---|
014 | property refMe : a reference to current application |
---|
015 | set appFileManager to refMe's NSFileManager's defaultManager() |
---|
016 | |
---|
017 | |
---|
018 | ################################### |
---|
019 | # 設定項目 |
---|
020 | #PayloadOrganization |
---|
021 | set strPayloadOrganization to ("com.cocolog-nifty.quicktimer") |
---|
022 | #有効期間 X日間有効 |
---|
023 | set numPeriodDate to (7) as integer |
---|
024 | |
---|
025 | ################################### |
---|
026 | #ダイアログ |
---|
027 | set strName to (name of current application) as text |
---|
028 | if strName is "osascript" then |
---|
029 | tell application "Finder" to activate |
---|
030 | else |
---|
031 | tell current application to activate |
---|
032 | end if |
---|
033 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask)) |
---|
034 | set ocidLibraryDirPathURL to ocidURLsArray's firstObject() |
---|
035 | set ocidFontsDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Fonts") isDirectory:(true) |
---|
036 | set aliasFontsDirPath to (ocidFontsDirPathURL's absoluteURL()) as alias |
---|
037 | # TTF と OTFのみ コレクションフォントは仕様上の対象外 |
---|
038 | set listUTI to {"public.truetype-ttf-font", "public.opentype-font"} as list |
---|
039 | set strMes to ("フォントファイルを選んでください") as text |
---|
040 | set strPrompt to ("フォントファイルを選んでください") as text |
---|
041 | try |
---|
042 | set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasFontsDirPath) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias |
---|
043 | on error |
---|
044 | log "エラーしました" |
---|
045 | return "エラーしました" |
---|
046 | end try |
---|
047 | ## |
---|
048 | set strFilePath to (POSIX path of aliasFilePath) as text |
---|
049 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
---|
050 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
---|
051 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
---|
052 | set ocidFileName to ocidFilePathURL's lastPathComponent() |
---|
053 | set ocidBaseFileName to ocidFileName's stringByDeletingPathExtension() |
---|
054 | |
---|
055 | ################################### |
---|
056 | # 保存先 |
---|
057 | set appFileManager to refMe's NSFileManager's defaultManager() |
---|
058 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDocumentDirectory) inDomains:(refMe's NSUserDomainMask)) |
---|
059 | set ocidDocumentDirPathURL to ocidURLsArray's firstObject() |
---|
060 | set ocidSaveDirPathURL to ocidDocumentDirPathURL's URLByAppendingPathComponent:("Mobileconfig") isDirectory:(true) |
---|
061 | # |
---|
062 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
---|
063 | # 777-->511 755-->493 700-->448 766-->502 |
---|
064 | ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions) |
---|
065 | set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
---|
066 | if (item 1 of listDone) is true then |
---|
067 | log "createDirectoryAtURL 正常処理" |
---|
068 | else if (item 2 of listDone) ≠ (missing value) then |
---|
069 | log (item 2 of listDone)'s code() as text |
---|
070 | log (item 2 of listDone)'s localizedDescription() as text |
---|
071 | return "createDirectoryAtURL エラーしました" |
---|
072 | end if |
---|
073 | # |
---|
074 | set strSaveFileName to ("com.apple.font." & ocidBaseFileName & ".mobileconfig") as text |
---|
075 | set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(true) |
---|
076 | |
---|
077 | |
---|
078 | ################################### |
---|
079 | # NSDataに読み込んで |
---|
080 | set listResponse to refMe's NSData's dataWithContentsOfURL:(ocidFilePathURL) options:(refMe's NSDataWritingAtomic) |error| :(reference) |
---|
081 | if (item 2 of listResponse) = (missing value) then |
---|
082 | log "dataWithContentsOfURL 正常処理" |
---|
083 | set ocidReadData to (item 1 of listResponse) |
---|
084 | else if (item 2 of listResponse) ≠ (missing value) then |
---|
085 | log (item 2 of listResponse)'s code() as text |
---|
086 | log (item 2 of listResponse)'s localizedDescription() as text |
---|
087 | return "dataWithContentsOfURL エラーしました" |
---|
088 | end if |
---|
089 | ########################## |
---|
090 | #PLIST作成部分 |
---|
091 | ########################## |
---|
092 | ##有効期限 |
---|
093 | |
---|
094 | ##【ROOT】 |
---|
095 | set ocidPlistDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0) |
---|
096 | # |
---|
097 | set ocidSetValue to (5) as integer |
---|
098 | (ocidPlistDict's setValue:(ocidSetValue) forKey:"TargetDeviceType") |
---|
099 | # |
---|
100 | set ocidSetValue to (doGetDateNo("yyyyMMdd")) as integer |
---|
101 | (ocidPlistDict's setValue:(ocidSetValue) forKey:"PayloadVersion") |
---|
102 | # |
---|
103 | set ocidUUID to refMe's NSUUID's alloc()'s init() |
---|
104 | set ocidSetValueUUID to ocidUUID's UUIDString as text |
---|
105 | (ocidPlistDict's setValue:(ocidSetValueUUID) forKey:"PayloadUUID") |
---|
106 | # |
---|
107 | set ocidSetValue to ("User") as text |
---|
108 | (ocidPlistDict's setValue:(ocidSetValue) forKey:"PayloadScope") |
---|
109 | # |
---|
110 | set ocidSetValue to false as boolean |
---|
111 | (ocidPlistDict's setValue:(ocidSetValue) forKey:"PayloadRemovalDisallowed") |
---|
112 | # |
---|
113 | set ocidSetValue to (strPayloadOrganization) as text |
---|
114 | (ocidPlistDict's setValue:(ocidSetValue) forKey:"PayloadOrganization") |
---|
115 | # |
---|
116 | set ocidSetValue to ("Configuration") as text |
---|
117 | (ocidPlistDict's setValue:(ocidSetValue) forKey:"PayloadType") |
---|
118 | # |
---|
119 | set ocidSetValue to ("com.apple.font." & ocidSetValueUUID) as text |
---|
120 | (ocidPlistDict's setValue:(ocidSetValue) forKey:"PayloadIdentifier") |
---|
121 | # |
---|
122 | set ocidSetValue to (strPayloadOrganization & "." & ocidBaseFileName) as text |
---|
123 | (ocidPlistDict's setValue:(ocidSetValue) forKey:"PayloadDisplayName") |
---|
124 | # |
---|
125 | set ocidSetValue to (strPayloadOrganization & "から提供されたフォント\n" & ocidBaseFileName & "になります\n印字・印刷の確認以外の用途での利用を禁止します") as text |
---|
126 | (ocidPlistDict's setValue:(ocidSetValue) forKey:"PayloadDescription") |
---|
127 | # |
---|
128 | set datePeriodDay to doGetPeriodDate(numPeriodDate) as date |
---|
129 | set strPeriodDay to datePeriodDay as text |
---|
130 | set ocidSetDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
---|
131 | ocidSetDict's setValue:("フォントをインストールします\n期日" & strPeriodDay & "まで\n利用できます\n印字・印刷の確認以外の用途での利用を禁止します") forKey:("default") |
---|
132 | (ocidPlistDict's setObject:(ocidSetDict) forKey:"ConsentText") |
---|
133 | # |
---|
134 | set ocidPeriodDay to doGetPeriodDate(numPeriodDate) |
---|
135 | (ocidPlistDict's setObject:(ocidPeriodDay) forKey:"RemovalDate") |
---|
136 | |
---|
137 | ########################## |
---|
138 | ##【PayloadContent】 |
---|
139 | set ocidPayloadDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0) |
---|
140 | # |
---|
141 | (ocidPayloadDict's setObject:(ocidReadData) forKey:"Font") |
---|
142 | # |
---|
143 | (ocidPayloadDict's setObject:(ocidBaseFileName) forKey:"Name") |
---|
144 | # |
---|
145 | (ocidPayloadDict's setObject:(ocidFileName) forKey:"FileName") |
---|
146 | # |
---|
147 | set ocidSetValue to (doGetDateNo("yyyyMMdd")) as integer |
---|
148 | (ocidPayloadDict's setValue:(ocidSetValue) forKey:"PayloadVersion") |
---|
149 | # |
---|
150 | set ocidUUID to refMe's NSUUID's alloc()'s init() |
---|
151 | set ocidSetValueUUID to ocidUUID's UUIDString as text |
---|
152 | (ocidPayloadDict's setValue:(ocidSetValueUUID) forKey:"PayloadUUID") |
---|
153 | # |
---|
154 | set ocidSetValue to ("com.apple.font") as text |
---|
155 | (ocidPayloadDict's setValue:(ocidSetValue) forKey:"PayloadType") |
---|
156 | # |
---|
157 | set ocidSetValue to ("com.apple.font." & ocidSetValueUUID) as text |
---|
158 | (ocidPayloadDict's setValue:(ocidSetValue) forKey:"PayloadIdentifier") |
---|
159 | # |
---|
160 | set ocidSetValue to ("com.apple.font") as text |
---|
161 | (ocidPayloadDict's setValue:(ocidSetValue) forKey:"PayloadDisplayName") |
---|
162 | # |
---|
163 | set ocidSetValue to (strPayloadOrganization & "から提供されたフォント\n印字・印刷の確認以外の用途での利用を禁止します") as text |
---|
164 | (ocidPayloadDict's setValue:(ocidSetValue) forKey:"PayloadDescription") |
---|
165 | # |
---|
166 | set ocidPayloadArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
---|
167 | ocidPayloadArrayM's addObject:(ocidPayloadDict) |
---|
168 | (ocidPlistDict's setObject:(ocidPayloadArrayM) forKey:"PayloadContent") |
---|
169 | |
---|
170 | |
---|
171 | ########################## |
---|
172 | #NSPropertyListSerialization |
---|
173 | set ocidFormat to (refMe's NSPropertyListXMLFormat_v1_0) |
---|
174 | set ocidPlistSerial to (refMe's NSPropertyListSerialization) |
---|
175 | set listResponse to (ocidPlistSerial's dataWithPropertyList:(ocidPlistDict) format:(ocidFormat) options:0 |error| :(reference)) |
---|
176 | if (item 2 of listResponse) = (missing value) then |
---|
177 | log "NSPropertyListSerialization 正常処理" |
---|
178 | set ocidPlistData to (item 1 of listResponse) |
---|
179 | else if (item 2 of listResponse) ≠ (missing value) then |
---|
180 | log (item 2 of listResponse)'s code() as text |
---|
181 | log (item 2 of listResponse)'s localizedDescription() as text |
---|
182 | return "NSPropertyListSerialization エラーしました" |
---|
183 | end if |
---|
184 | ########################## |
---|
185 | #保存 |
---|
186 | set listDone to (ocidPlistData's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error| :(reference)) |
---|
187 | if (item 1 of listDone) is true then |
---|
188 | log "writeToURL 正常終了" |
---|
189 | else if (item 1 of listDone) is false then |
---|
190 | return "writeToURL 保存に失敗しました" |
---|
191 | end if |
---|
192 | |
---|
193 | |
---|
194 | ################################### |
---|
195 | #保存先を開く |
---|
196 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
---|
197 | set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL) |
---|
198 | if (boolDone) is true then |
---|
199 | return "openURL 正常処理" |
---|
200 | else |
---|
201 | set aliasSaveDirPath to (ocidSaveDirPathURL's absoluteURL()) as alias |
---|
202 | tell application "Finder" |
---|
203 | open folder aliasSaveDirPath |
---|
204 | end tell |
---|
205 | return "openURL エラーしました" |
---|
206 | end if |
---|
207 | |
---|
208 | return |
---|
209 | |
---|
210 | |
---|
211 | |
---|
212 | ############################## |
---|
213 | ### 今の日付日間 テキスト |
---|
214 | ############################## |
---|
215 | to doGetDateNo(argDateFormat) |
---|
216 | ####日付情報の取得 |
---|
217 | set ocidDate to current application's NSDate's |date|() |
---|
218 | ###日付のフォーマットを定義 |
---|
219 | set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init() |
---|
220 | ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX") |
---|
221 | set ocidTimeZone to refMe's NSTimeZone's alloc()'s initWithName:"Asia/Tokyo" |
---|
222 | ocidNSDateFormatter's setTimeZone:(ocidTimeZone) |
---|
223 | ocidNSDateFormatter's setDateFormat:(argDateFormat) |
---|
224 | set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate |
---|
225 | set strDateAndTime to ocidDateAndTime as text |
---|
226 | return strDateAndTime |
---|
227 | end doGetDateNo |
---|
228 | |
---|
229 | |
---|
230 | ########################## |
---|
231 | #有効期間の日付作成 |
---|
232 | ########################## |
---|
233 | to doGetPeriodDate(argPeriodDateNo) |
---|
234 | ####今の日付時間 |
---|
235 | set ocidNowDate to refMe's NSDate's |date|() |
---|
236 | ####カレンダー初期化 |
---|
237 | set ocidNowCalendar to refMe's NSCalendar's alloc()'s initWithCalendarIdentifier:(refMe's NSGregorianCalendar) |
---|
238 | ####日付時間コンポーネント |
---|
239 | set ocidDateComponent to refMe's NSDateComponents's alloc()'s init() |
---|
240 | ####指定の日付を足す |
---|
241 | ocidDateComponent's setDay:(argPeriodDateNo) |
---|
242 | ####カレンダーオプション |
---|
243 | set ocidOption to (refMe's NSCalendarWrapComponents) |
---|
244 | ####今のカレンダーにコンポーネント分の値を追加する |
---|
245 | set ocidPeriodDate to ocidNowCalendar's dateByAddingComponents:ocidDateComponent toDate:ocidNowDate options:ocidOption |
---|
246 | return ocidPeriodDate |
---|
247 | end doGetPeriodDate |
---|