« Adobe Reader ダウンロードURLリスト(v24)更新 | トップページ | [savedSearch]フォント用 保存済みの検索条件 (文字セット別) »

[savedSearch]保存済みの検索条件(2日以内に変更があるもの)(仮)


あくまでも参考にしてください

【スクリプトエディタで開く】 |

サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#com.cocolog-nifty.quicktimer.icefloe
004# 留意事項 検索条件は上書きされます
005# 前面ウィンドウのパスで拡張子検索
006(*
007検索条件のカスタマイズはMDitem
008https://developer.apple.com/documentation/coreservices/file_metadata/mditem?language=objc
009*)
010----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
011use AppleScript version "2.8"
012use framework "Foundation"
013use framework "AppKit"
014use scripting additions
015
016property refMe : a reference to current application
017
018
019##########################################
020##検索パスと名称のレコード
021set recordKeyPath to {|Desktop|:"デスクトップ", |Pictures|:"ピクチャー", |Documents|:"書類", |Movies|:"ムービー", |Music|:"ミュージック", |Sites|:"サイト", |Downloads|:"ダウンロード"} as record
022set ocidKeyPathDict to refMe's NSMutableDictionary's alloc()'s initWithDictionary:(recordKeyPath)
023
024##########################################
025##キーの数だけ繰り返し
026set ocidAllKeys to ocidKeyPathDict's allKeys()
027repeat with itemKey in ocidAllKeys
028  set ocidValue to (ocidKeyPathDict's valueForKey:(itemKey))
029  set ocidSaveDirPathURL to doMakeSavedSearch({itemKey, ocidValue})
030end repeat
031
032##########################################
033##場所を示す savedSearchファイルをFinderで開く
034set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
035set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL)
036
037
038
039##########################################
040##ファイル生成サブ
041to doMakeSavedSearch({argPath, argSaveName})
042  set strPath to argPath as text
043  set strSaveName to argSaveName as text
044  ##########################################
045    set appFileManager to refMe's NSFileManager's defaultManager()
046  set ocidUserName to refMe's NSUserName()
047  set strUserName to ocidUserName as text
048  ####【1】検索ルートパス
049  set ocidUserName to refMe's NSUserName()
050  set strUserName to ocidUserName as text
051  ##FXScopeパス
052  set strFXScopePath to ("/System/Volumes/Data/Users/" & strUserName & "/" & strPath) as text
053  set ocidFXScopePathStr to refMe's NSString's stringWithString:(strFXScopePath)
054  set ocidFXScopePath to ocidFXScopePathStr's stringByStandardizingPath()
055  set ocidFXScopePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFXScopePath) isDirectory:(false)
056  set ocidFXScopeDirFileName to ocidFXScopePathURL's lastPathComponent()
057  set ocidFXScopePath to ocidFXScopePathURL's |path|()
058  ##DirPath
059  set ocidHomeDirURL to appFileManager's homeDirectoryForCurrentUser()
060  set ocidCurrentFolderPathURL to ocidHomeDirURL's URLByAppendingPathComponent:(strPath) isDirectory:(true)
061  set ocidCurrentFolderPath to ocidCurrentFolderPathURL's |path|()
062  ###  FXScopeのスコープ番号を取得
063  set listResponse to (ocidFXScopePathURL's getResourceValue:(reference) forKey:(refMe's NSURLFileContentIdentifierKey) |error| :(reference))
064  if (item 1 of listResponse) is (true) then
065    log "正常処理"
066    set ocidScopeNo to (item 2 of listResponse)
067  else if (item 3 of listResponse) ≠ (missing value) then
068    log (item 3 of listResponse)'s code() as text
069    log (item 3 of listResponse)'s localizedDescription() as text
070    return "FXScopeでエラーしました"
071  end if
072  
073  ###PLIST(savedSearch)保存先 ディレクトリ
074  set appFileManager to refMe's NSFileManager's defaultManager()
075  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDocumentDirectory) inDomains:(refMe's NSUserDomainMask))
076  set ocidDocumentDirPathURL to ocidURLsArray's firstObject()
077  set ocidSaveDirPathURL to ocidDocumentDirPathURL's URLByAppendingPathComponent:("Saved Searches/直近検索") isDirectory:true
078  ###フォルダを作る
079  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
080  ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
081  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
082  ###localizedを作る
083  set ocidNulText to refMe's NSString's stringWithString:("")
084  set ocidLocalizedPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(".localized")
085  set listDone to ocidNulText's writeToURL:(ocidLocalizedPathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
086  if (item 1 of listDone) is true then
087    log "保存先フォルダ作成正常処理"
088  else if (item 2 of listDone) ≠ (missing value) then
089    log (item 2 of listDone)'s code() as text
090    log (item 2 of listDone)'s localizedDescription() as text
091    return "保存先フォルダ作成 エラーしました"
092  end if
093  ##
094  set strFileName to (strSaveName & "-2日以内.savedSearch") as text
095  set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
096  
097  ##########################################
098  ####【5】PLIST=DICT= savedSearch新規作成
099  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
100  
101  ########【A】ROOT
102  #ROOTに追加
103  ocidPlistDict's setValue:(1 as integer) forKey:"CompatibleVersion"
104  #ROOTに追加
105  set strSetValue to "InRange(kMDItemContentModificationDate,$time.today(-2d),$time.today(+1d))" as text
106  ocidPlistDict's setValue:(strSetValue) forKey:"RawQuery"
107  ########【B】SuggestedAttributes
108  set ocidSetArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
109  #ROOTに追加
110  ocidPlistDict's setObject:(ocidSetArray) forKey:"SuggestedAttributes"
111  ########【C】ViewSettings
112  set ocidViewSettingsDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
113  ###【C-1】WindowState
114  set ocidSetDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
115  ocidSetDict's setValue:(true as boolean) forKey:("ContainerShowSidebar")
116  ocidSetDict's setValue:(true as boolean) forKey:("ShowSidebar")
117  ocidSetDict's setValue:(true as boolean) forKey:("ShowStatusBar")
118  ocidSetDict's setValue:(true as boolean) forKey:("ShowTabView")
119  ocidSetDict's setValue:(true as boolean) forKey:("ShowToolbar")
120  ocidSetDict's setValue:({{0, 50}, {720, 520}}) forKey:("WindowBounds")
121  ocidViewSettingsDict's setObject:(ocidSetDict) forKey:("WindowState")
122  ###【C-2】ListViewSettings
123  set ocidSetDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
124  ocidSetDict's setValue:(true as boolean) forKey:("calculateAllSizes")
125  ocidSetDict's setValue:(true as boolean) forKey:("showIconPreview")
126  ocidSetDict's setValue:(false as boolean) forKey:("useRelativeDates")
127  ocidSetDict's setValue:(13 as integer) forKey:("axTextSize")
128  ocidSetDict's setValue:(16 as integer) forKey:("iconSize")
129  ocidSetDict's setValue:(13 as integer) forKey:("textSize")
130  ocidSetDict's setValue:(13 as integer) forKey:("viewOptionsVersion")
131  ocidSetDict's setValue:("dateLastOpened" as string) forKey:("sortColumn")
132  ocidViewSettingsDict's setObject:(ocidSetDict) forKey:("ListViewSettings")
133  ###【C-3】ExtendedListViewSettingsV2
134  set ocidSetDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
135  ocidSetDict's setValue:(true as boolean) forKey:("calculateAllSizes")
136  ocidSetDict's setValue:(true as boolean) forKey:("showIconPreview")
137  ocidSetDict's setValue:(false as boolean) forKey:("useRelativeDates")
138  ocidSetDict's setValue:(13 as integer) forKey:("axTextSize")
139  ocidSetDict's setValue:(16 as integer) forKey:("iconSize")
140  ocidSetDict's setValue:(13 as integer) forKey:("textSize")
141  ocidSetDict's setValue:(1 as integer) forKey:("viewOptionsVersion")
142  ocidSetDict's setValue:("dateLastOpened" as string) forKey:("sortColumn")
143  ocidViewSettingsDict's setObject:(ocidSetDict) forKey:("ExtendedListViewSettingsV2")
144  ###ViewSettingsmをROOTに追加
145  ocidPlistDict's setObject:(ocidViewSettingsDict) forKey:"ViewSettings"
146  ########【D】SearchCriteria
147  #ROOTにセットするレコード
148  set ocidSearchCriteriaDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
149  ##【D-1】スコープ番号
150  ocidSearchCriteriaDict's setValue:(ocidScopeNo) forKey:("FXScope")
151  (*  FXScopeArrayOfPaths
152#全件
153kMDQueryScopeHome
154kMDQueryScopeComputer
155kMDQueryScopeNetwork
156#牽引あり
157kMDQueryScopeAllIndexed
158kMDQueryScopeComputerIndexed
159kMDQueryScopeNetworkIndexed
160#パス指定スコープ指定混在の場合
161set listSetValue to {ocidFXScopePath, "kMDQueryScopeAllIndexed"} as list
162set ocidSetArray to refMe's NSMutableArray's alloc()'s initWithArray:(listSetValue)
163*)
164  ##【D-2】FXScopeArrayOfPaths
165  set ocidSetArray to refMe's NSMutableArray's arrayWithObject:(ocidCurrentFolderPath)
166  ocidSearchCriteriaDict's setObject:(ocidSetArray) forKey:("FXScopeArrayOfPaths")
167  ##【D-3】CurrentFolderPath
168  set ocidSetArray to refMe's NSMutableArray's arrayWithObject:(ocidCurrentFolderPath)
169  ocidSearchCriteriaDict's setObject:(ocidSetArray) forKey:"CurrentFolderPath"
170  ##【D-4】FXCriteriaSlices
171  set ocidSetDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
172  #
173  set listSetValue to {"kMDItemContentModificationDate", 800, 801, 900, 901} as list
174  set ocidSetArray to refMe's NSMutableArray's alloc()'s initWithArray:(listSetValue)
175  ocidSetDict's setObject:(ocidSetArray) forKey:("criteria")
176  #
177  set listSetValue to {"コンテンツの変更日", "is", "within last", "2", "days"} as list
178  set ocidSetArray to refMe's NSMutableArray's alloc()'s initWithArray:(listSetValue)
179  ocidSetDict's setObject:(ocidSetArray) forKey:("displayValues")
180  #
181  ocidSetDict's setValue:(0 as integer) forKey:("rowType")
182  #
183  set ocidSetChildArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
184  ocidSetDict's setObject:(ocidSetChildArray) forKey:("subrows")
185  #
186  set ocidSetArray to refMe's NSMutableArray's arrayWithObject:(ocidSetDict)
187  ocidSearchCriteriaDict's setObject:(ocidSetArray) forKey:"FXCriteriaSlices"
188  #ROOTに追加
189  ocidPlistDict's setObject:(ocidSearchCriteriaDict) forKey:"SearchCriteria"
190  
191  ########【E】RawQueryDict
192  set ocidRawQueryDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
193  ##【E-1】 FinderFilesOnly
194  ocidRawQueryDict's setValue:(true as boolean) forKey:("FinderFilesOnly")
195  ##【E-2】UserFilesOnly
196  ocidRawQueryDict's setValue:(true as boolean) forKey:("UserFilesOnly")
197  ##【E-3】kMDItemGroupId
198  (*    kMDItemGroupId
1997=ムービー
2008=実行可能=APP
2019=フォルダ
20210=音楽
20311=PDF
20412=プレゼンテーション
20513=画像
206set strSetValue to "(_kMDItemGroupId = 7)" as text
207
208kMDItemContentTypeTree
209kMDItemContentTypeTree= UTI
210kMDItemContentTypeTree = public.text
211
212set strSetValue to "(_kMDItemContentTypeTree = public.text)" as text
213
214
215/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Metadata.tbd
216kMDItemAdamID
217kMDItemContentChangeDate
218kMDItemCreationDate
219kMDItemCreatorCode
220kMDItemExportImporterAvaliable
221kMDItemFSContentType
222kMDItemFSContentTypeTree
223kMDItemFSDisplayName
224kMDItemFileName
225kMDItemFinderFlags
226kMDItemFinderLabel
227kMDItemHasCustomIcon
228kMDItemHasExtensionHidden
229kMDItemImporterResult
230kMDItemInvisibleFileType
231kMDItemIsEvictedFile
232kMDItemIsExtensionHidden
233kMDItemIsStationery
234kMDItemLocked
235kMDItemNodeCount
236kMDItemOwnerGroupID
237kMDItemOwnerUserID
238kMDItemPrescanCandidate
239kMDItemServerVersion
240kMDItemSortIdentityAttr
241kMDItemStaticInterestScore
242kMDItemSupportFileType
243kMDItemTextContentIndexExists
244kMDItemTypeCode
245kMDItemUserTags
246kMDItemAcquisitionMake
247kMDItemAcquisitionModel
248kMDItemAlbum
249kMDItemAlternateNames
250kMDItemAltitude
251kMDItemAperture
252kMDItemAppleLoopDescriptors
253kMDItemAppleLoopsKeyFilterType
254kMDItemAppleLoopsLoopMode
255kMDItemAppleLoopsRootKey
256kMDItemApplicationCategories
257kMDItemAttributeChangeDate
258kMDItemAudiences
259kMDItemAudioBitRate
260kMDItemAudioChannelCount
261kMDItemAudioEncodingApplication
262kMDItemAudioSampleRate
263kMDItemAudioTrackNumber
264kMDItemAuthorAddresses
265kMDItemAuthorEmailAddresses
266kMDItemAuthors
267kMDItemBitsPerSample
268kMDItemCFBundleIdentifier
269kMDItemCameraOwner
270kMDItemCity
271kMDItemCodecs
272kMDItemColorSpace
273kMDItemComment
274kMDItemComposer
275kMDItemContactKeywords
276kMDItemContentCreationDate
277kMDItemContentModificationDate
278kMDItemContentType
279kMDItemContentTypeTree
280kMDItemContributors
281kMDItemCopyright
282kMDItemCountry
283kMDItemCoverage
284kMDItemCreator
285kMDItemDateAdded
286kMDItemDeliveryType
287kMDItemDescription
288kMDItemDestinationRecipients
289kMDItemDidChangeNotification
290kMDItemDirector
291kMDItemDisplayName
292kMDItemDisplayNameInitials
293kMDItemDocumentContainer
294kMDItemDownloadedDate
295kMDItemDueDate
296kMDItemDurationSeconds
297kMDItemEXIFGPSVersion
298kMDItemEXIFVersion
299kMDItemEditors
300kMDItemEmailAddresses
301kMDItemEncodingApplications
302kMDItemExecutableArchitectures
303kMDItemExecutablePlatform
304kMDItemExposureMode
305kMDItemExposureProgram
306kMDItemExposureTimeSeconds
307kMDItemExposureTimeString
308kMDItemFNumber
309kMDItemFSContentChangeDate
310kMDItemFSCreationDate
311kMDItemFSCreatorCode
312kMDItemFSExists
313kMDItemFSFinderFlags
314kMDItemFSHasCustomIcon
315kMDItemFSInvisible
316kMDItemFSIsExtensionHidden
317kMDItemFSIsReadable
318kMDItemFSIsStationery
319kMDItemFSIsWriteable
320kMDItemFSLabel
321kMDItemFSName
322kMDItemFSNodeCount
323kMDItemFSOwnerGroupID
324kMDItemFSOwnerUserID
325kMDItemFSSize
326kMDItemFSTypeCode
327kMDItemFinderComment
328kMDItemFinderOpenDate
329kMDItemFlashOnOff
330kMDItemFocalLength
331kMDItemFocalLength35mm
332kMDItemFonts
333kMDItemGPSAreaInformation
334kMDItemGPSDOP
335kMDItemGPSDateStamp
336kMDItemGPSDestBearing
337kMDItemGPSDestDistance
338kMDItemGPSDestLatitude
339kMDItemGPSDestLongitude
340kMDItemGPSDifferental
341kMDItemGPSMapDatum
342kMDItemGPSMeasureMode
343kMDItemGPSProcessingMethod
344kMDItemGPSStatus
345kMDItemGPSTrack
346kMDItemGenre
347kMDItemHTMLContent
348kMDItemHasAlphaChannel
349kMDItemHeadline
350kMDItemISOSpeed
351kMDItemIdentifier
352kMDItemImageDirection
353kMDItemInformation
354kMDItemInstantMessageAddresses
355kMDItemInstructions
356kMDItemIsApplicationManaged
357kMDItemIsGeneralMIDISequence
358kMDItemIsLikelyJunk
359kMDItemIsQuarantined
360kMDItemKeySignature
361kMDItemKeywords
362kMDItemKind
363kMDItemLabelID
364kMDItemLabelIcon
365kMDItemLabelKind
366kMDItemLabelUUID
367kMDItemLanguages
368kMDItemLastUsedDate
369kMDItemLatitude
370kMDItemLayerNames
371kMDItemLensModel
372kMDItemLogicalSize
373kMDItemLongitude
374kMDItemLyricist
375kMDItemMaxAperture
376kMDItemMediaTypes
377kMDItemMeteringMode
378kMDItemMusicalGenre
379kMDItemMusicalInstrumentCategory
380kMDItemMusicalInstrumentName
381kMDItemNamedLocation
382kMDItemNumberOfPages
383kMDItemOrganizations
384kMDItemOrientation
385kMDItemOriginApplicationIdentifier
386kMDItemOriginMessageID
387kMDItemOriginSenderDisplayName
388kMDItemOriginSenderHandle
389kMDItemOriginSubject
390kMDItemOriginalFormat
391kMDItemOriginalSource
392kMDItemPageHeight
393kMDItemPageWidth
394kMDItemParticipants
395kMDItemPath
396kMDItemPerformers
397kMDItemPhoneNumbers
398kMDItemPhysicalSize
399kMDItemPixelCount
400kMDItemPixelHeight
401kMDItemPixelWidth
402kMDItemProducer
403kMDItemProfileName
404kMDItemProjects
405kMDItemPublishers
406kMDItemPurchaseDate
407kMDItemRecipientAddresses
408kMDItemRecipientEmailAddresses
409kMDItemRecipients
410kMDItemRecordingDate
411kMDItemRecordingYear
412kMDItemRedEyeOnOff
413kMDItemResolutionHeightDPI
414kMDItemResolutionWidthDPI
415kMDItemRights
416kMDItemSecurityMethod
417kMDItemSpeed
418kMDItemStarRating
419kMDItemStateOrProvince
420kMDItemStreamable
421kMDItemSubject
422kMDItemSupportFileType
423kMDItemTempo
424kMDItemTextContent
425kMDItemTheme
426kMDItemTimeSignature
427kMDItemTimestamp
428kMDItemTitle
429kMDItemTotalBitRate
430kMDItemURL
431kMDItemUsedDates
432kMDItemUserTags
433kMDItemVersion
434kMDItemVideoBitRate
435kMDItemWhereFroms
436kMDItemWhiteBalance
437#ファイル またはディレクトリ名
438set strSetValue to "(_kMDItemFileName = \"*." & strExName & "\"c)" as text
439*)
440  
441  #3日以内
442  set strSetValue to "InRange(kMDItemContentModificationDate,$time.today(-2d),$time.today(+1d))" as text
443  ocidRawQueryDict's setValue:(strSetValue) forKey:"RawQuery"
444  ##【E-4】SearchScopes
445  (* SearchScopes
446https://developer.apple.com/documentation/coreservices/file_metadata/mdquery/query_search_scope_keys?language=objc
447#全件
448kMDQueryScopeHome
449kMDQueryScopeComputer
450kMDQueryScopeNetwork
451#牽引あり
452kMDQueryScopeAllIndexed
453kMDQueryScopeComputerIndexed
454kMDQueryScopeNetworkIndexed
455#牽引されている内容から検索
456set listSetValue to {"kMDQueryScopeAllIndexed"} as list
457#全件対象
458set listSetValue to {"kMDQueryScopeHome", "kMDQueryScopeComputer", "kMDQueryScopeNetwork"} as list
459#牽引されている内容から検索+ホームディレクトリは全件
460set listSetValue to {"kMDQueryScopeHome", "kMDQueryScopeComputerIndexed", "kMDQueryScopeNetworkIndexed"} as list
461#SearchScopes指定の場合
462set ocidChildArray to refMe's NSMutableArray's alloc()'s initWithArray:(listSetValue)
463*)
464  #パス指定の場合
465  set ocidChildArray to refMe's NSMutableArray's arrayWithObject:(ocidFXScopePath)
466  #親Arrayにセットして
467  set ocidSetArray to refMe's NSMutableArray's alloc()'s initWithArray:(ocidChildArray)
468  #SearchScopesにセットする
469  ocidRawQueryDict's setObject:(ocidSetArray) forKey:("SearchScopes")
470  #ROOTに追加
471  ocidPlistDict's setObject:(ocidRawQueryDict) forKey:("RawQueryDict")
472  
473  
474  
475  ##########################################
476  ####【6】PLISTに変換 (optionは 0-2  Immutable /MutableContainers /MutableContainersAndLeaves)
477  set ocidFromat to refMe's NSPropertyListXMLFormat_v1_0
478  set listResponse to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFromat) options:0  |error| :(reference)
479  if (item 2 of listResponse) = (missing value) then
480    log "正常処理"
481    set ocidPlistEditData to (item 1 of listResponse)
482  else if (item 2 of listResponse) ≠ (missing value) then
483    log (item 2 of listResponse)'s code() as text
484    log (item 2 of listResponse)'s localizedDescription() as text
485    return "シリアライゼーションでエラーしました"
486  end if
487  
488  ##########################################
489  ####【7】保存
490  set listDone to ocidPlistEditData's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error| :(reference)
491  if (item 2 of listDone) = (missing value) then
492    log "正常処理"
493    set ocidPlistEditData to (item 1 of listDone)
494  else if (item 2 of listDone) ≠ (missing value) then
495    log (item 2 of listDone)'s code() as text
496    log (item 2 of listDone)'s localizedDescription() as text
497    return "保存でエラーしました"
498  end if
499  
500  return ocidSaveDirPathURL
501end doMakeSavedSearch
AppleScriptで生成しました

|

« Adobe Reader ダウンロードURLリスト(v24)更新 | トップページ | [savedSearch]フォント用 保存済みの検索条件 (文字セット別) »

AppleScript XML savedSearch」カテゴリの記事