[Desktop]デスクトップのポジションの保存と復帰 (ファイルやフォルダの移動に対応)
デスクトップのポジションを保存
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # デスクトップポジション保存 v2 |
004 | (* |
005 | APFS以外の外部ドライブ |
006 | クラウドストレージ への移動はサポートしていません |
007 | 基本的にはローカルディスク内での移動を戻すだけです |
008 | *) |
009 | #com.cocolog-nifty.quicktimer.icefloe |
010 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
011 | use AppleScript version "2.8" |
012 | use framework "Foundation" |
013 | use framework "AppKit" |
014 | use scripting additions |
015 | |
016 | property refMe : a reference to current application |
017 | |
018 | ######################################## |
019 | ####前処理 ファイルとパス |
020 | ######################################## |
021 | set appFileManager to refMe's NSFileManager's defaultManager() |
022 | ##設定ファイル保存先 |
023 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask)) |
024 | set ocidApplicatioocidupportDirPathURL to ocidURLsArray's firstObject() |
025 | set ocidSaveDirPathURL to ocidApplicatioocidupportDirPathURL's URLByAppendingPathComponent:("com.cocolog-nifty.quicktimer/Desktop PositionV2") isDirectory:(true) |
026 | #フォルダの有無チェック |
027 | set ocidSaveDirPath to ocidSaveDirPathURL's |path|() |
028 | set boolDirExists to appFileManager's fileExistsAtPath:(ocidSaveDirPath) isDirectory:(true) |
029 | if boolDirExists = true then |
030 | log "すでにフォルダはあります" |
031 | else if boolDirExists = false then |
032 | log "フォルダが無いのでつくります" |
033 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
034 | ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions) |
035 | set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
036 | if (item 2 of listDone) ≠ (missing value) then |
037 | log (item 2 of listDone)'s localizedDescription() as text |
038 | return "フォルダ作成でエラーしました" |
039 | end if |
040 | end if |
041 | #設定ファイルの有無チェック |
042 | set ocidPlistPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("com.apple.finder.desktoppositionV2.plist") isDirectory:(false) |
043 | set ocidPlistPath to ocidPlistPathURL's |path|() |
044 | set boolDirExists to appFileManager's fileExistsAtPath:(ocidPlistPath) isDirectory:(false) |
045 | if boolDirExists = true then |
046 | log "ファイルがあります" |
047 | else if boolDirExists = false then |
048 | log "ファイルが無いので空のPLISTを作っておきます" |
049 | #空のDICT |
050 | set ocidBlankDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:(0) |
051 | #キーアーカイブ形式で保存する |
052 | set listResponse to refMe's NSKeyedArchiver's archivedDataWithRootObject:(ocidBlankDict) requiringSecureCoding:(false) |error| :(reference) |
053 | set ocidSfl3Data to (item 1 of listResponse) |
054 | if (item 2 of listResponse) ≠ (missing value) then |
055 | log (item 2 of listDone)'s localizedDescription() as text |
056 | return "アーカイブに失敗しました" |
057 | end if |
058 | #保存 |
059 | set listDone to ocidSfl3Data's writeToURL:(ocidPlistPathURL) options:0 |error| :(reference) |
060 | if (item 2 of listDone) ≠ (missing value) then |
061 | log (item 2 of listDone)'s localizedDescription() as text |
062 | return "ファイルの保存に失敗しました" |
063 | end if |
064 | end if |
065 | ######################################## |
066 | ####ポジションファイルバックアップ |
067 | ######################################## |
068 | set strDateNO to doGetNextDateNo({"yyyyMMddhhmmss", 1}) as string |
069 | set strBackupFileName to ("com.apple.finder.desktopposition." & strDateNO & ".plist") |
070 | set ocidBackUpPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strBackupFileName) isDirectory:(false) |
071 | |
072 | set appFileManager to refMe's NSFileManager's defaultManager() |
073 | set listDone to (appFileManager's copyItemAtURL:(ocidPlistPathURL) toURL:(ocidBackUpPathURL) |error| :(reference)) |
074 | |
075 | |
076 | ######################################## |
077 | ####ポジション収集 |
078 | ######################################## |
079 | #ポジションを格納するArray |
080 | set ocidPositionArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:(0)) |
081 | #ブックマーク用のキーリスト |
082 | set ocidKeysArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
083 | ocidKeysArray's addObject:(refMe's NSURLPathKey) |
084 | ocidKeysArray's addObject:(refMe's NSURLFileResourceIdentifierKey) |
085 | ocidKeysArray's addObject:(refMe's NSURLVolumeIdentifierKey) |
086 | |
087 | #ボジションの収集 |
088 | tell application "Finder" |
089 | repeat with itemDesktopItem in desktop |
090 | tell itemDesktopItem |
091 | #格納するキー |
092 | set strKey to (name) as text |
093 | #格納する値 |
094 | set listPosition to (desktop position) as list |
095 | set strURL to (URL) as text |
096 | end tell |
097 | ##ブックマークを取得して |
098 | set ocidItemURL to (refMe's NSURL's URLWithString:(strURL)) |
099 | set listDone to (ocidItemURL's bookmarkDataWithOptions:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:(ocidKeysArray) relativeToURL:(missing value) |error| :(specifier)) |
100 | set ocdiBookMarkData to (item 1 of listDone) |
101 | #格納用のDICTに格納していく |
102 | set ocidSetValueDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:(0)) |
103 | (ocidSetValueDict's setObject:(strKey) forKey:("name")) |
104 | (ocidSetValueDict's setObject:(listPosition) forKey:("desktop position")) |
105 | (ocidSetValueDict's setObject:(ocidItemURL) forKey:("URL")) |
106 | (ocidSetValueDict's setObject:(ocdiBookMarkData) forKey:("BookMark")) |
107 | #Arrayにセット |
108 | (ocidPositionArray's addObject:(ocidSetValueDict)) |
109 | end repeat |
110 | end tell |
111 | set ocidSaveDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:(0)) |
112 | ocidSaveDict's setObject:(ocidPositionArray) forKey:("DesktopItems") |
113 | ######################################## |
114 | ####保存 |
115 | ######################################## |
116 | #キーアーカイブ形式で保存する |
117 | set listResponse to refMe's NSKeyedArchiver's archivedDataWithRootObject:(ocidSaveDict) requiringSecureCoding:(false) |error| :(reference) |
118 | set ocidSfl3Data to (item 1 of listResponse) |
119 | if (item 2 of listResponse) ≠ (missing value) then |
120 | log (item 2 of listDone)'s localizedDescription() as text |
121 | return "アーカイブに失敗しました" |
122 | end if |
123 | #保存 |
124 | set listDone to ocidSfl3Data's writeToURL:(ocidPlistPathURL) options:0 |error| :(reference) |
125 | if (item 2 of listDone) ≠ (missing value) then |
126 | log (item 2 of listDone)'s localizedDescription() as text |
127 | return "ファイルの保存に失敗しました" |
128 | end if |
129 | |
130 | return "ポジションを保存しました" |
131 | |
132 | |
133 | |
134 | |
135 | ################################ |
136 | # 明日の日付 doGetDateNo(argDateFormat,argCalendarNO) |
137 | # argCalendarNO 1 NSCalendarIdentifierGregorian 西暦 |
138 | # argCalendarNO 2 NSCalendarIdentifierJapanese 和暦 |
139 | ################################ |
140 | to doGetNextDateNo({argDateFormat, argCalendarNO}) |
141 | ##渡された値をテキストで確定させて |
142 | set strDateFormat to argDateFormat as text |
143 | set intCalendarNO to argCalendarNO as integer |
144 | ###日付情報の取得 |
145 | set ocidDate to current application's NSDate's |date|() |
146 | set ocidIntervalt to current application's NSDate's dateWithTimeIntervalSinceNow:(86400) |
147 | ###日付のフォーマットを定義(日本語) |
148 | set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init() |
149 | ###和暦 西暦 カレンダー分岐 |
150 | if intCalendarNO = 1 then |
151 | set ocidCalendarID to (current application's NSCalendarIdentifierGregorian) |
152 | else if intCalendarNO = 2 then |
153 | set ocidCalendarID to (current application's NSCalendarIdentifierJapanese) |
154 | else |
155 | set ocidCalendarID to (current application's NSCalendarIdentifierISO8601) |
156 | end if |
157 | set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID) |
158 | set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo") |
159 | set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX") |
160 | ###設定 |
161 | ocidFormatterJP's setTimeZone:(ocidTimezoneJP) |
162 | ocidFormatterJP's setLocale:(ocidLocaleJP) |
163 | ocidFormatterJP's setCalendar:(ocidCalendarJP) |
164 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterNoStyle) |
165 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterShortStyle) |
166 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterMediumStyle) |
167 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterLongStyle) |
168 | ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle) |
169 | ###渡された値でフォーマット定義 |
170 | ocidFormatterJP's setDateFormat:(strDateFormat) |
171 | ###フォーマット適応 |
172 | set ocidDateAndTime to ocidFormatterJP's stringFromDate:(ocidIntervalt) |
173 | ###テキストで戻す |
174 | set strDateAndTime to ocidDateAndTime as text |
175 | return strDateAndTime |
176 | end doGetNextDateNo |
177 | return |
AppleScriptで生成しました |
デスクトップを復帰
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # デスクトップポジション復帰 v2 |
004 | (* |
005 | APFS以外の外部ドライブ |
006 | クラウドストレージ への移動はサポートしていません |
007 | 基本的にはローカルディスク内での移動を戻すだけです |
008 | *) |
009 | #com.cocolog-nifty.quicktimer.icefloe |
010 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
011 | use AppleScript version "2.8" |
012 | use framework "Foundation" |
013 | use framework "AppKit" |
014 | use scripting additions |
015 | |
016 | property refMe : a reference to current application |
017 | |
018 | ######################################## |
019 | ####前処理 ファイルとパス |
020 | ######################################## |
021 | set appFileManager to refMe's NSFileManager's defaultManager() |
022 | ##設定ファイル保存先 |
023 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask)) |
024 | set ocidApplicatioocidupportDirPathURL to ocidURLsArray's firstObject() |
025 | set ocidSaveDirPathURL to ocidApplicatioocidupportDirPathURL's URLByAppendingPathComponent:("com.cocolog-nifty.quicktimer/Desktop PositionV2") isDirectory:(true) |
026 | #設定ファイルの有無チェック |
027 | set ocidPlistPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("com.apple.finder.desktoppositionV2.plist") isDirectory:(false) |
028 | set ocidPlistPath to ocidPlistPathURL's |path|() |
029 | set boolDirExists to appFileManager's fileExistsAtPath:(ocidPlistPath) isDirectory:(true) |
030 | if boolDirExists = true then |
031 | # log "ファイルがあります" |
032 | else if boolDirExists = false then |
033 | log "ファイルが無いので処理を終了します" |
034 | return "ファイルが無いので処理を終了します" |
035 | end if |
036 | ##処理に必要なのでデスクトップのURLを生成しておく |
037 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
038 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
039 | |
040 | ######################################## |
041 | ####PLIST読み込み |
042 | ######################################## |
043 | #データ読み込み DATAとして読み込む |
044 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
045 | set listResponse to (refMe's NSData's dataWithContentsOfURL:(ocidPlistPathURL) options:(ocidOption) |error| :(reference)) |
046 | if (item 2 of listResponse) ≠ (missing value) then |
047 | log (item 2 of listResponse)'s localizedDescription() as text |
048 | return "ファイルのデータ読み込みに失敗しました" |
049 | else if (item 2 of listResponse) = (missing value) then |
050 | set ocidPlistData to (item 1 of listResponse) |
051 | end if |
052 | #DATAを解凍する |
053 | set ocidClassListArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:(0)) |
054 | (ocidClassListArray's addObject:(refMe's NSDictionary)) |
055 | (ocidClassListArray's addObject:(refMe's NSMutableDictionary)) |
056 | (ocidClassListArray's addObject:(refMe's NSArray)) |
057 | (ocidClassListArray's addObject:(refMe's NSMutableArray)) |
058 | (ocidClassListArray's addObject:(refMe's NSObject's classForCoder)) |
059 | (ocidClassListArray's addObject:(refMe's NSObject's classForKeyedArchiver)) |
060 | (ocidClassListArray's addObject:(refMe's NSObject's classForKeyedUnarchiver)) |
061 | #クラスセット |
062 | set ocidSetClass to refMe's NSSet's alloc()'s initWithArray:(ocidClassListArray) |
063 | #解凍 |
064 | set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClasses:(ocidSetClass) fromData:(ocidPlistData) |error| :(reference) |
065 | if (item 2 of listResponse) ≠ (missing value) then |
066 | log (item 2 of listResponse)'s localizedDescription() as text |
067 | return "データをPLISTに解凍するのに失敗しました" |
068 | else if (item 2 of listResponse) = (missing value) then |
069 | set ocidPlistDict to (item 1 of listResponse) |
070 | end if |
071 | ######################################## |
072 | ####ポジションデータの処理 |
073 | ######################################## |
074 | set boolMiisngValue to (missing value) |
075 | #Array取り出し |
076 | set ocidPositionArray to ocidPlistDict's objectForKey:("DesktopItems") |
077 | repeat with itemArray in ocidPositionArray |
078 | set ocidSetValueDict to itemArray |
079 | set listPosition to (ocidSetValueDict's valueForKey:("desktop position")) as list |
080 | set strKey to (ocidSetValueDict's valueForKey:("name")) as text |
081 | ##URL |
082 | set ocidOriginalURL to (ocidSetValueDict's objectForKey:("URL")) |
083 | set ocidOriginalFilePath to ocidOriginalURL's |path|() |
084 | ##BOOKMARKデータをURLにする |
085 | set ocdiBookMarkData to (ocidSetValueDict's objectForKey:("BookMark")) |
086 | set listResponse to (refMe's NSURL's URLByResolvingBookmarkData:(ocdiBookMarkData) options:(refMe's NSURLBookmarkResolutionWithoutUI) relativeToURL:(missing value) bookmarkDataIsStale:(missing value) |error| :(reference)) |
087 | set ocidBookMarkURL to (item 1 of listResponse) |
088 | ###移動先判定開始▼ |
089 | if ocidBookMarkURL = (missing value) then |
090 | #ブックマークが参照できない状態かゴミ箱に入れて消去済み=処理対象外 |
091 | set strMes to (strKey & "は、すでに消去されか?\r外部ドライブにあります\r処理しません") as text |
092 | display alert strMes buttons {"OK", "中断"} default button "OK" cancel button "中断" as informational giving up after 2 |
093 | #処理するか?のBOOL |
094 | set boolChkWork to false as boolean |
095 | set boolMiisngValue to true as boolean |
096 | else |
097 | #ブックマークが参照可能な状態 |
098 | set ocidBookMarkPath to ocidBookMarkURL's |path|() |
099 | ##URLとBOOKマークデータの相違を確認 |
100 | set boolSameURL to (ocidOriginalURL's isEqual:(ocidBookMarkURL)) as boolean |
101 | if boolSameURL is true then |
102 | ##移動していない=処理対象 |
103 | #処理するか?のBOOL |
104 | set boolChkWork to true as boolean |
105 | else |
106 | ##移動している |
107 | if (ocidBookMarkPath as text) contains "/.Trash/" then |
108 | ##今ゴミ箱にあります |
109 | set strMes to (strKey & "は、今ゴミ箱にあります戻しますか?") as text |
110 | set recordResponse to (display alert strMes buttons {"戻さない", "戻す", "中断"} default button "戻さない" cancel button "中断" as informational giving up after 5) as record |
111 | set strBottonName to (button returned of recordResponse) as text |
112 | if "戻す" is equal to (strBottonName) then |
113 | #戻す=処理対象 |
114 | #処理するか?のBOOL |
115 | set boolChkWork to true as boolean |
116 | set listDone to (appFileManager's moveItemAtURL:(ocidBookMarkURL) toURL:(ocidOriginalURL) |error| :(reference)) |
117 | if (item 1 of listDone) is false then |
118 | set strMes to (strKey & "移動に失敗しました") as text |
119 | display alert strMes buttons {"OK", "中断"} default button "OK" cancel button "中断" as informational giving up after 2 |
120 | end if |
121 | else if "戻さない" is equal to (strBottonName) then |
122 | #戻さない=処理対象外 |
123 | #処理するか?のBOOL |
124 | set boolChkWork to false as boolean |
125 | end if |
126 | else |
127 | set boolChkWork to true as boolean |
128 | set listDone to (appFileManager's moveItemAtURL:(ocidBookMarkURL) toURL:(ocidOriginalURL) |error| :(reference)) |
129 | if (item 1 of listDone) is false then |
130 | set strMes to (strKey & "移動に失敗しました") as text |
131 | display alert strMes buttons {"OK", "中断"} default button "OK" cancel button "中断" as informational giving up after 2 |
132 | end if |
133 | end if |
134 | end if |
135 | end if |
136 | log strKey |
137 | |
138 | if boolChkWork is true then |
139 | set aliasOriginalPath to (ocidOriginalURL's absoluteURL()) as alias |
140 | tell application "Finder" |
141 | set desktop position of item strKey to listPosition |
142 | end tell |
143 | end if |
144 | |
145 | end repeat |
146 | |
147 | |
148 | if boolMiisngValue is true then |
149 | set strMes to "保存したポジション情報が古くなっています更新してください" |
150 | display alert strMes as informational giving up after 2 |
151 | return "保存したポジション情報が古くなっています更新してください" |
152 | else |
153 | return "処理終了" |
154 | end if |
155 | |
156 | |
AppleScriptで生成しました |
ファイルを選んで復帰
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # デスクトップポジション復帰 v2 |
004 | (* |
005 | APFS以外の外部ドライブ |
006 | クラウドストレージ への移動はサポートしていません |
007 | 基本的にはローカルディスク内での移動を戻すだけです |
008 | *) |
009 | #com.cocolog-nifty.quicktimer.icefloe |
010 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
011 | use AppleScript version "2.8" |
012 | use framework "Foundation" |
013 | use framework "AppKit" |
014 | use scripting additions |
015 | |
016 | property refMe : a reference to current application |
017 | |
018 | ######################################## |
019 | ####前処理 ファイルとパス |
020 | ######################################## |
021 | set appFileManager to refMe's NSFileManager's defaultManager() |
022 | ##設定ファイル保存先 |
023 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask)) |
024 | set ocidApplicatioocidupportDirPathURL to ocidURLsArray's firstObject() |
025 | set ocidSaveDirPathURL to ocidApplicatioocidupportDirPathURL's URLByAppendingPathComponent:("com.cocolog-nifty.quicktimer/Desktop PositionV2") isDirectory:(true) |
026 | set aliasDefaultLocation to (ocidSaveDirPathURL's absoluteURL()) as alias |
027 | ############################# |
028 | ###ダイアログを前面に出す |
029 | set strName to (name of current application) as text |
030 | if strName is "osascript" then |
031 | tell application "Finder" to activate |
032 | else |
033 | tell current application to activate |
034 | end if |
035 | |
036 | set listUTI to {"com.apple.property-list"} as list |
037 | set strMes to ("ファイルを選んでください") as text |
038 | set strPrompt to ("ファイルを選んでください") as text |
039 | try |
040 | ### ファイル選択時 |
041 | set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias |
042 | on error |
043 | log "エラーしました" |
044 | return "エラーしました" |
045 | end try |
046 | set strFilePath to (POSIX path of aliasFilePath) as text |
047 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
048 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
049 | set ocidPlistPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
050 | |
051 | #設定ファイルの有無チェック |
052 | |
053 | set ocidPlistPath to ocidPlistPathURL's |path|() |
054 | set boolDirExists to appFileManager's fileExistsAtPath:(ocidPlistPath) isDirectory:(true) |
055 | if boolDirExists = true then |
056 | # log "ファイルがあります" |
057 | else if boolDirExists = false then |
058 | log "ファイルが無いので処理を終了します" |
059 | return "ファイルが無いので処理を終了します" |
060 | end if |
061 | ##処理に必要なのでデスクトップのURLを生成しておく |
062 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
063 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
064 | |
065 | ######################################## |
066 | ####PLIST読み込み |
067 | ######################################## |
068 | #データ読み込み DATAとして読み込む |
069 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
070 | set listResponse to (refMe's NSData's dataWithContentsOfURL:(ocidPlistPathURL) options:(ocidOption) |error| :(reference)) |
071 | if (item 2 of listResponse) ≠ (missing value) then |
072 | log (item 2 of listResponse)'s localizedDescription() as text |
073 | return "ファイルのデータ読み込みに失敗しました" |
074 | else if (item 2 of listResponse) = (missing value) then |
075 | set ocidPlistData to (item 1 of listResponse) |
076 | end if |
077 | #DATAを解凍する |
078 | set ocidClassListArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:(0)) |
079 | (ocidClassListArray's addObject:(refMe's NSDictionary)) |
080 | (ocidClassListArray's addObject:(refMe's NSMutableDictionary)) |
081 | (ocidClassListArray's addObject:(refMe's NSArray)) |
082 | (ocidClassListArray's addObject:(refMe's NSMutableArray)) |
083 | (ocidClassListArray's addObject:(refMe's NSObject's classForCoder)) |
084 | (ocidClassListArray's addObject:(refMe's NSObject's classForKeyedArchiver)) |
085 | (ocidClassListArray's addObject:(refMe's NSObject's classForKeyedUnarchiver)) |
086 | #クラスセット |
087 | set ocidSetClass to refMe's NSSet's alloc()'s initWithArray:(ocidClassListArray) |
088 | #解凍 |
089 | set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClasses:(ocidSetClass) fromData:(ocidPlistData) |error| :(reference) |
090 | if (item 2 of listResponse) ≠ (missing value) then |
091 | log (item 2 of listResponse)'s localizedDescription() as text |
092 | return "データをPLISTに解凍するのに失敗しました" |
093 | else if (item 2 of listResponse) = (missing value) then |
094 | set ocidPlistDict to (item 1 of listResponse) |
095 | end if |
096 | ######################################## |
097 | ####ポジションデータの処理 |
098 | ######################################## |
099 | set boolMiisngValue to (missing value) |
100 | #Array取り出し |
101 | set ocidPositionArray to ocidPlistDict's objectForKey:("DesktopItems") |
102 | repeat with itemArray in ocidPositionArray |
103 | set ocidSetValueDict to itemArray |
104 | set listPosition to (ocidSetValueDict's valueForKey:("desktop position")) as list |
105 | set strKey to (ocidSetValueDict's valueForKey:("name")) as text |
106 | ##URL |
107 | set ocidOriginalURL to (ocidSetValueDict's objectForKey:("URL")) |
108 | set ocidOriginalFilePath to ocidOriginalURL's |path|() |
109 | ##BOOKMARKデータをURLにする |
110 | set ocdiBookMarkData to (ocidSetValueDict's objectForKey:("BookMark")) |
111 | set listResponse to (refMe's NSURL's URLByResolvingBookmarkData:(ocdiBookMarkData) options:(refMe's NSURLBookmarkResolutionWithoutUI) relativeToURL:(missing value) bookmarkDataIsStale:(missing value) |error| :(reference)) |
112 | set ocidBookMarkURL to (item 1 of listResponse) |
113 | ###移動先判定開始▼ |
114 | if ocidBookMarkURL = (missing value) then |
115 | #ブックマークが参照できない状態かゴミ箱に入れて消去済み=処理対象外 |
116 | set strMes to (strKey & "は、すでに消去されか?\r外部ドライブにあります\r処理しません") as text |
117 | display alert strMes buttons {"OK", "中断"} default button "OK" cancel button "中断" as informational giving up after 2 |
118 | #処理するか?のBOOL |
119 | set boolChkWork to false as boolean |
120 | set boolMiisngValue to true as boolean |
121 | else |
122 | #ブックマークが参照可能な状態 |
123 | set ocidBookMarkPath to ocidBookMarkURL's |path|() |
124 | ##URLとBOOKマークデータの相違を確認 |
125 | set boolSameURL to (ocidOriginalURL's isEqual:(ocidBookMarkURL)) as boolean |
126 | if boolSameURL is true then |
127 | ##移動していない=処理対象 |
128 | #処理するか?のBOOL |
129 | set boolChkWork to true as boolean |
130 | else |
131 | ##移動している |
132 | if (ocidBookMarkPath as text) contains "/.Trash/" then |
133 | ##今ゴミ箱にあります |
134 | set strMes to (strKey & "は、今ゴミ箱にあります戻しますか?") as text |
135 | set recordResponse to (display alert strMes buttons {"戻さない", "戻す", "中断"} default button "戻さない" cancel button "中断" as informational giving up after 5) as record |
136 | set strBottonName to (button returned of recordResponse) as text |
137 | if "戻す" is equal to (strBottonName) then |
138 | #戻す=処理対象 |
139 | #処理するか?のBOOL |
140 | set boolChkWork to true as boolean |
141 | set listDone to (appFileManager's moveItemAtURL:(ocidBookMarkURL) toURL:(ocidOriginalURL) |error| :(reference)) |
142 | if (item 1 of listDone) is false then |
143 | set strMes to (strKey & "移動に失敗しました") as text |
144 | display alert strMes buttons {"OK", "中断"} default button "OK" cancel button "中断" as informational giving up after 2 |
145 | end if |
146 | else if "戻さない" is equal to (strBottonName) then |
147 | #戻さない=処理対象外 |
148 | #処理するか?のBOOL |
149 | set boolChkWork to false as boolean |
150 | end if |
151 | else |
152 | set boolChkWork to true as boolean |
153 | set listDone to (appFileManager's moveItemAtURL:(ocidBookMarkURL) toURL:(ocidOriginalURL) |error| :(reference)) |
154 | if (item 1 of listDone) is false then |
155 | set strMes to (strKey & "移動に失敗しました") as text |
156 | display alert strMes buttons {"OK", "中断"} default button "OK" cancel button "中断" as informational giving up after 2 |
157 | end if |
158 | end if |
159 | end if |
160 | end if |
161 | log strKey |
162 | |
163 | if boolChkWork is true then |
164 | set aliasOriginalPath to (ocidOriginalURL's absoluteURL()) as alias |
165 | tell application "Finder" |
166 | set desktop position of item strKey to listPosition |
167 | end tell |
168 | end if |
169 | |
170 | end repeat |
171 | |
172 | |
173 | if boolMiisngValue is true then |
174 | set strMes to "保存したポジション情報が古くなっています更新してください" |
175 | display alert strMes as informational giving up after 2 |
176 | return "保存したポジション情報が古くなっています更新してください" |
177 | else |
178 | return "処理終了" |
179 | end if |
180 | |
AppleScriptで生成しました |
| 固定リンク