AppleScript XML savedSearch

savedSearch=スマートフォルダのアイコン

OSに標準でインストールされているicnsファイルのパス一覧
https://quicktimer.cocolog-nifty.com/icefloe/2024/05/post-25168d.html
にあるように

202405230700291138x125

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

サンプルソース(参考)
行番号ソース
001#パスは
002/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/SmartFolderIcon.icns
AppleScriptで生成しました

|

[savedSearch]フォント用 保存済みの検索条件 (文字セット別)

202405150211381176x516

ダウンロード - Fonts_文字セット別.zip

|

[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で生成しました

|

[savedSearch]前面ウィンドウをrootで拡張子検索(途中)

ダウンロード -拡張子検索.zip


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
# 留意事項 検索条件は上書きされます
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

#################################
##ファイルパスの収集
tell application "Finder"
  set aliasPathToMe to path to me as alias
  set aliasContainerDir to container of aliasPathToMe as alias
  set aliasSavedSearchDir to (folder "savedSearch" of folder aliasContainerDir) as alias
  set listFilePath to (get every item of aliasSavedSearchDir) as list
  log listFilePath
end tell
#################################
##ファイルパス→エイリアスパス
set listAliasPath to {} as list
repeat with itemFilePath in listFilePath
  set aliasFilePath to itemFilePath as alias
  set end of listAliasPath to aliasFilePath
end repeat
log listAliasPath
#################################
##エイリアスパス→ファイル名のリスト
set listFileName to {} as list
repeat with itemAliasPath in listAliasPath
  tell application "Finder"
    set strFileName to name of itemAliasPath as text
  end tell
  set end of listFileName to strFileName
end repeat
log listFileName
#################################
##ダイアログ
try
  ###ダイアログを前面に出す
  tell current application
    set strName to name as text
  end tell
  ####スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder"
      activate
    end tell
  else
    tell current application
      activate
    end tell
  end if
  set listResponse to (choose from list listFileName with title "選んでください" with prompt "選んでください" default items (item 1 of listFileName) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
  log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
end if
set strFileName to (item 1 of listResponse) as text

tell application "Finder"
  set aliasFilePath to (file strFileName of folder aliasSavedSearchDir) as alias
end tell
set strSearchFilePath to (POSIX path of aliasFilePath) as text

#################################
##起動時に削除される項目
tell application "Finder"
  set aliasTemporaryPath to path to temporary items from local domain as alias with folder creation
end tell
set strTemporaryPath to (POSIX path of aliasTemporaryPath) as text

###読み込みPLISTパス
set ocidTemplateFilePath to refMe's NSString's stringWithString:(strSearchFilePath)
set ocidTemplatePath to ocidTemplateFilePath's stringByStandardizingPath()
set ocidTemplatePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidTemplatePath) isDirectory:false)

###SavePlistPath
set ocidTemporaryPathStr to refMe's NSString's stringWithString:(strTemporaryPath)
set ocidTemporaryPath to ocidTemporaryPathStr's stringByStandardizingPath()
set ocidTemporaryPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidTemporaryPath) isDirectory:true)
set ocidSavedFileURL to ocidTemporaryPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
#################################
##前面のFinderウィンドウのパスを取得
tell application "Finder"
  tell front Finder window
    set fileTargetPath to target
  end tell
  set aliasTargetPath to fileTargetPath as alias
end tell
set strFXScopePath to (POSIX path of aliasTargetPath) as text
#################################
##前面FinderWindowのBoundsを取得
tell application "Finder"
  tell front Finder window
    set listbounds to bounds
  end tell
end tell
#################################
##bound to rect
set numX to item 1 of listbounds as number
set numY to item 2 of listbounds as number
set numWidth to item 3 of listbounds as number
set numHeight to item 4 of listbounds as number
####
##位置を右下へ10
set numX to numX + 10 as number
set numY to numY + 10 as number
###注意 テキストです
set strWindowBounds to "{{" & numX & "," & numY & "},{" & numWidth & "," & numHeight & "}}" as text

##FXScopeArrayOfPaths
set ocidFXScopePathStr to refMe's NSString's stringWithString:(strFXScopePath)
set ocidFXScopePath to ocidFXScopePathStr's stringByStandardizingPath()
set strFXScopePath to ocidFXScopePath as text

##SearchScopes
set strSearchScopesPath to ("/System/Volumes/Data" & strFXScopePath & "") as text
set ocidSearchScopesPathStr to refMe's NSString's stringWithString:(strSearchScopesPath)
set ocidSearchScopesPath to ocidSearchScopesPathStr's stringByStandardizingPath()
set strSearchScopesPath to ocidSearchScopesPath as text

#################################
####PLIST編集
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidTemplatePathURL)
set ocidRawQuery to ocidPlistDict's objectForKey:"RawQueryDict"
set ocidSearchScopes to ocidRawQuery's objectForKey:"SearchScopes"
set ocidNestArray to ocidSearchScopes's firstObject()
ocidNestArray's replaceObjectAtIndex:0 withObject:(strSearchScopesPath)
####
set ocidSearchCriteria to ocidPlistDict's objectForKey:"SearchCriteria"
set ocidFXScope to ocidSearchCriteria's objectForKey:"FXScopeArrayOfPaths"
ocidFXScope's replaceObjectAtIndex:0 withObject:(strFXScopePath)
####
set ocidViewSettings to ocidPlistDict's objectForKey:"ViewSettings"
set ocidWindowState to ocidViewSettings's objectForKey:"WindowState"
ocidWindowState's setValue:(strWindowBounds) forKey:("WindowBounds")

#################################
####保存
set boolDone to ocidPlistDict's writeToURL:(ocidSavedFileURL) atomically:true
log boolDone
set ocidSaveFilePath to ocidSavedFileURL's |path|()

###場所を示す
set ocidSharedWorkSpace to refMe's NSWorkspace's sharedWorkspace()

set strUTI to "com.apple.finder"
set ocidAppBundle to refMe's NSBundle's bundleWithIdentifier:(strUTI)
###
if ocidAppBundle is not (missing value) then
  set ocidAppBundlePathURL to ocidAppBundle's bundleURL()
  set strFilePath to ocidAppBundlePathURL's |path|() as text
else
  set ocidAppBundlePathURL to appNSWorkspace's URLForApplicationWithBundleIdentifier:(strUTI)
  set ocidAppBundle to refMe's NSBundle's bundleWithURL:(ocidAppBundlePathURL)
  set strFilePath to ocidAppBundlePathURL's |path|() as text
end if
set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue
set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue
set ocidConfig to refMe's NSWorkspaceOpenConfiguration's configuration()
ocidConfig's setHides:ocidFalse
ocidConfig's setRequiresUniversalLinks:ocidFalse
ocidConfig's setActivates:ocidTrue

ocidSharedWorkSpace's openURLs:{ocidSavedFileURL} withApplicationAtURL:(ocidAppBundlePathURL) configuration:(ocidConfig) completionHandler:(missing value)

return


|

[savedSearch]検索条件ファイルを作成する

ダウンロード - makenewsavedseach.zip


テンプレートとなるPLISTを内包していますので
試す場合は↑をダウンロードしてお試しください
全部値を入れるの面倒だったのでテンプレートになるplistの値を入れ替える方式にした


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
# 留意事項 検索条件は上書きされます
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()

###ファイル名=表示名
set strFileName to "iCloud Driveを検索.savedSearch"
###検索対象のパス
set strFXScopePath to "~/Library/Mobile Documents" as text

#################################
tell application "Finder"
  set aliasPathToMe to path to me as alias
  set aliasContainerDir to container of aliasPathToMe as alias
  set aliasTemplateFilePath to (file "template.savedSearch" of folder "template" of folder aliasContainerDir) as alias
end tell
###読み込みPLISTパス
set strTemplateFilePath to (POSIX path of aliasTemplateFilePath) as text
set ocidTemplateFilePath to refMe's NSString's stringWithString:(strTemplateFilePath)
set ocidTemplatePath to ocidTemplateFilePath's stringByStandardizingPath()
set ocidTemplatePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidTemplatePath) isDirectory:false)

###SavePlistPath
set ocidURLArray to appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask)
set ocidLibraryDirPathURL to ocidURLArray's firstObject()
set ocidSavedSearchesURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Saved Searches") isDirectory:true
set ocidSavedFileURL to ocidSavedSearchesURL's URLByAppendingPathComponent:(strFileName) isDirectory:false

##FXScopeArrayOfPaths
set ocidFXScopePathStr to refMe's NSString's stringWithString:(strFXScopePath)
set ocidFXScopePath to ocidFXScopePathStr's stringByStandardizingPath()
set strFXScopePath to ocidFXScopePath as text

##SearchScopes
set strSearchScopesPath to ("/System/Volumes/Data" & strFXScopePath & "") as text
set ocidSearchScopesPathStr to refMe's NSString's stringWithString:(strSearchScopesPath)
set ocidSearchScopesPath to ocidSearchScopesPathStr's stringByStandardizingPath()
set strSearchScopesPath to ocidSearchScopesPath as text

#################################
####PLIST編集
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidTemplatePathURL)
set ocidRawQuery to ocidPlistDict's objectForKey:"RawQueryDict"
set ocidSearchScopes to ocidRawQuery's objectForKey:"SearchScopes"
set ocidNestArray to ocidSearchScopes's firstObject()
ocidNestArray's replaceObjectAtIndex:0 withObject:(strSearchScopesPath)
####
set ocidSearchCriteria to ocidPlistDict's objectForKey:"SearchCriteria"
set ocidFXScope to ocidSearchCriteria's objectForKey:"FXScopeArrayOfPaths"
ocidFXScope's replaceObjectAtIndex:0 withObject:(strFXScopePath)

#################################
####保存
set boolDone to ocidPlistDict's writeToURL:(ocidSavedFileURL) atomically:true
log boolDone
set ocidSaveFilePath to ocidSavedFileURL's |path|()

###場所を示す
set ocidSharedWorkSpace to refMe's NSWorkspace's sharedWorkspace()
ocidSharedWorkSpace's selectFile:(ocidSaveFilePath) inFileViewerRootedAtPath:"/"


return


|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat BookMark Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Open Acrobat Plugin Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat Sequ Acrobat Sign Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe RemoteUpdateManager Apple AppleScript AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Audio AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript Guide AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript Mail AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFileManager enumeratorAtURL AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Events Plist AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML savedSearch AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript XMP AppleScript YouTube AppleScript Zero Suppress Applications CityCode Design github iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom