001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | (* |
004 |
|
005 | OPEN/SAVEパネルのdefault location |
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 framework "UniformTypeIdentifiers" |
015 | use scripting additions |
016 |
|
017 | property refMe : a reference to current application |
018 |
|
019 | #設定項目 |
020 | #このパスをデフォルトとケーションとして設定する |
021 | set strDirPath to ("/tmp") as text |
022 |
|
023 | #設定項目 |
024 | #設定するアプリケーションのplistのパス |
025 | set strFilePath to "~/Library/Preferences/com.microsoft.edgemac.plist" as text |
026 |
|
027 |
|
028 |
|
029 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
030 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
031 | set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false) |
032 |
|
033 | #NSDATA |
034 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
035 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference) |
036 | if (item 2 of listResponse) = (missing value) then |
037 | log "initWithContentsOfURL 正常処理" |
038 | set ocidReadData to (item 1 of listResponse) |
039 | else if (item 2 of listResponse) ≠ (missing value) then |
040 | set strErrorNO to (item 2 of listResponse)'s code() as text |
041 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
042 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
043 | return "initWithContentsOfURL エラーしました" & strErrorNO & strErrorMes |
044 | end if |
045 | #NSPropertyListSerializationにする |
046 | set appPlistSerial to (refMe's NSPropertyListSerialization) |
047 | set ocidOption to (refMe's NSPropertyListMutableContainersAndLeaves) |
048 | set listResponse to appPlistSerial's propertyListWithData:(ocidReadData) options:(ocidOption) format:(reference) |error|:(reference) |
049 | log (count of listResponse) |
050 | if (item 3 of listResponse) = (missing value) then |
051 | set ocidPlistDict to (item 1 of listResponse) |
052 | set ocidFormat to (item 2 of listResponse) |
053 | else if (item 3 of listResponse) ≠ (missing value) then |
054 | set strErrorNO to (item 2 of listResponse)'s code() as text |
055 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
056 | current application's NSLog("■:" & strErrorNO & strErrorMes) |
057 | return "エラーしましたpropertyListWithData:" & strErrorNO & strErrorMes |
058 | end if |
059 |
|
060 | #NSURLBookmark |
061 | set ocidBookMarkData to ocidPlistDict's objectForKey:("NSOSPLastRootDirectory") |
062 |
|
063 | #BOOKMARKを変換パス |
064 | set ocidKeyArray to refMe's NSMutableArray's alloc()'s init() |
065 | ocidKeyArray's addObject:(refMe's NSURLPathKey) |
066 | ocidKeyArray's addObject:(refMe's NSURLNameKey) |
067 | set ocidResourceValues to refMe's NSURL's resourceValuesForKeys:(ocidKeyArray) fromBookmarkData:(ocidBookMarkData) |
068 | set ocidFilePath to (ocidResourceValues's objectForKey:(refMe's NSURLPathKey)) |
069 | log ocidFilePath as text |
070 |
|
071 | #BOOKMARKを変換ファイルURL |
072 | set ocidOption to (refMe's NSURLBookmarkResolutionWithoutUI) |
073 | set listResponse to refMe's NSURL's URLByResolvingBookmarkData:(ocidBookMarkData) options:(ocidOption) relativeToURL:(missing value) bookmarkDataIsStale:(false) |error|:(reference) |
074 | set ocidFileURL to (item 1 of listResponse) |
075 | log ocidFileURL's absoluteString() as text |
076 |
|
077 | #この値をセットしていく |
078 |
|
079 | set ocidDirPathStr to refMe's NSString's stringWithString:(strDirPath) |
080 | set ocidDirPath to ocidDirPathStr's stringByStandardizingPath() |
081 | set ocidDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDirPath) isDirectory:true) |
082 |
|
083 | #BOOKマークデータを作成して |
084 | set ocidOption to (refMe's NSURLBookmarkResolutionWithoutUI) |
085 | set listResponse to ocidDirPathURL's bookmarkDataWithOptions:(ocidOption) includingResourceValuesForKeys:(missing value) relativeToURL:(missing value) |error|:(reference) |
086 | set ocidSetBookmarkData to (item 1 of listResponse) |
087 |
|
088 |
|
089 | #セットして |
090 | ocidPlistDict's setObject:(ocidSetBookmarkData) forKey:("NSOSPLastRootDirectory") |
091 |
|
092 | #NSPropertyListSerialization |
093 | set listResponse to (refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFormat) options:(0) |error|:(reference)) |
094 | if (item 2 of listResponse) = (missing value) then |
095 | set ocidSaveData to (item 1 of listResponse) |
096 | else if (item 2 of listResponse) ≠ (missing value) then |
097 | set strErrorNO to (item 2 of listResponse)'s code() as text |
098 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
099 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
100 | return "エラーしましたdataWithPropertyList:" & strErrorNO & strErrorMes |
101 | end if |
102 |
|
103 | #NSDATAで保存 |
104 | set ocidOption to (refMe's NSDataWritingAtomic) |
105 | set listDone to (ocidSaveData's writeToURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference)) |
106 | if (item 2 of listResponse) ≠ (missing value) then |
107 | set strErrorNO to (item 2 of listResponse)'s code() as text |
108 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
109 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
110 | return "エラーしましたwriteToURL: " & strErrorNO & strErrorMes |
111 | end if |
112 |
|
113 |
|
114 |
|
115 |
|
116 | set strFilePath to ("~/Library/Preferences/com.apple.appkit.xpc.openAndSavePanelService.plist") as text |
117 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
118 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
119 | set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false) |
120 |
|
121 |
|
122 | set listResponse to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL) |error|:(reference) |
123 | if (item 2 of listResponse) = (missing value) then |
124 | set ocidXPCDict to (item 1 of listResponse) |
125 | else if (item 2 of listResponse) ≠ (missing value) then |
126 | set strErrorNO to (item 2 of listResponse)'s code() as text |
127 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
128 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
129 | return "エラーしました" & strErrorNO & strErrorMes |
130 | end if |
131 |
|
132 | set ocidRecentArray to ocidXPCDict's objectForKey:("NSOSPRecentPlaces") |
133 | ocidRecentArray's replaceObjectAtIndex:(0) withObject:(ocidSetBookmarkData) |
134 |
|
135 |
|
136 |
|
137 | set listDone to ocidXPCDict's writeToURL:(ocidFilePathURL) |error|:(reference) |
138 | if (item 1 of listDone) is true then |
139 | log "writeToURL 正常処理" |
140 | else if (item 2 of listDone) ≠ (missing value) then |
141 | set strErrorNO to (item 2 of listDone)'s code() as text |
142 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
143 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
144 | return "writeToURL エラーしました" & strErrorNO & strErrorMes |
145 | end if |