AppleScript Spotlight

[com.apple.finder] SlicesRootAttributes その2

 

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
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()


##########################################
###【1】ドキュメントのパスをNSString
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
##テスト用
##set ocidPlistFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/com.apple.finder.test.plist")
set ocidPlistFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/com.apple.finder.plist")
##########################################
### 【2】PLISTを可変レコードとして読み込み
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL)

##########################################
### 【3】処理はここで
set ocidSlicesRootArray to (ocidPlistDict's objectForKey:("SlicesRootAttributes"))
if ocidSlicesRootArray = (missing value) then
log "未設定なので設定します"
  set listkMDitem to {"kMDItemKind", "kMDItemLastUsedDate", "kMDItemContentModificationDate", "kMDItemContentCreationDate", "kMDItemDisplayName", "kMDItemTextContent", "com_apple_FileExtensionAttribute", "kMDItemFSInvisible", "kMDItemBitsPerSample", "kMDItemFSName", "kMDItemFSSize", "kMDItemPixelCount", "kMDItemOrientation", "kMDItemDurationSeconds", "kMDItemPixelWidth", "kMDItemPixelHeight", "kMDItemFSLabel", "kMDItemMediaTypes", "kMDItemColorSpace", "kMDItemFonts", "kMDItemPageWidth", "kMDItemFSContentChangeDate", "kMDItemFSCreationDate", "kMDItemEmailAddresses", "kMDItemPageHeight", "kMDItemFSNodeCount", "kMDItemLayerNames"} as list
  set ocidSlicesRootArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidSlicesRootArray's setArray:(listkMDitem)
ocidPlistDict's setObject:(ocidSlicesRootArray) forKey:("SlicesRootAttributes")
else
  ###項目の有無確認 ラベル追加
  set strTBID to ("kMDItemFSLabel") as text
  set boolValue to ocidSlicesRootArray's containsObject:(strTBID)
  if boolValue = false then
log "未設定なので設定します"
    set ocidSetValue to refMe's NSString's stringWithString:(strTBID)
ocidSlicesRootArray's addObject:(ocidSetValue)
  else
log "すでに設定済み"
  end if
end if
###項目の有無確認 タグ追加
set strTBID to ("kMDItemUserTags") as text
set boolValue to ocidSlicesRootArray's containsObject:(strTBID)
if boolValue = false then
log "未設定なので設定します"
  set ocidSetValue to refMe's NSString's stringWithString:(strTBID)
ocidSlicesRootArray's addObject:(ocidSetValue)
else
log "すでに設定済み"
end if
##########################################
####【4】保存 ここは上書き
set boolDone to ocidPlistDict's writeToURL:(ocidPlistFilePathURL) atomically:true
-->システムファイルなの書き込めないので書き込み失敗でfalseが返る
log boolDone


##########################################
####【5】リロード

if boolDone = true then
  tell application "Finder" to quit
  repeat 1 times
delay 1
    #####CFPreferencesを再起動
    set strCommandText to "/usr/bin/killall cfprefsd" as text
do shell script strCommandText
delay 1
  end repeat
  
  tell application "Finder" to activate
return "正常終了"
else
return "保存に失敗しました"
end if



return "処理終了"

|

[com.apple.metadata]bash ファイルのメタデータ情報をXMLplistに書き出す


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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
##path to me このファイルのパス
STR_PATH_TO_ME="${BASH_SOURCE[0]}"
##パス指定する場合はこちらにフルパスを
STR_FILE_PATH="$STR_PATH_TO_ME"
##コンテナディレクトリ
STR_CONTAINER_DIR_PATH=$(/usr/bin/dirname "$STR_FILE_PATH")
##ファイル名
STR_FILE_NAME=$(/usr/bin/basename "$STR_FILE_PATH")
##ベースファイル名
STR_BASE_NAME="${STR_FILE_NAME%.*}"
##保存先ディレクトリ
STR_BASE_FILE_PATH="${STR_CONTAINER_DIR_PATH}/${STR_BASE_NAME}"
##保存先を作成
/bin/mkdir -p "$STR_BASE_FILE_PATH"

###主要メタデータリスト
LIST_ATTR_NAME=(com.apple.metadata:kMDItemApplicationCategories com.apple.metadata:kMDItemAuthors com.apple.metadata:kMDItemComment com.apple.metadata:kMDItemCopyright com.apple.metadata:kMDItemCreator com.apple.metadata:kMDItemDescription com.apple.metadata:kMDItemFinderComment com.apple.metadata:kMDItemHeadline com.apple.metadata:kMDItemInformation com.apple.metadata:kMDItemKeywords com.apple.metadata:kMDItemKind com.apple.metadata:kMDItemLanguages com.apple.metadata:kMDItemProjects com.apple.metadata:kMDItemSubject com.apple.metadata:kMDItemTitle com.apple.metadata:kMDItemVersion)

###メタデータリストの数だけ繰り返し
for ITEM_ATTR_NAME in "${LIST_ATTR_NAME[@]}"
do
##ファイル名用に文字列置換
STR_PLIST_FILE_NAME=$(/bin/echo "$ITEM_ATTR_NAME" | /usr/bin/tr ':' '.')
##保存先パス
STR_SAVE_FILE_PATH="${STR_BASE_FILE_PATH}/${STR_PLIST_FILE_NAME}.plist"
##データをPLISTのXML形式で取得
STR_PLIST_DATA=$(/usr/bin/xattr -px "$ITEM_ATTR_NAME" "$STR_FILE_PATH" |  /usr/bin/xxd -r -p | /usr/bin/plutil -convert xml1 -o - -)
##ファイルに書き出す
/bin/echo "$STR_PLIST_DATA" > "$STR_SAVE_FILE_PATH"
done


exit 0


|

[com.apple.metadata]bash ファイルのバージョンを今日の日付にする


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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#################################
###パス
##path to me このファイルのパス
STR_PATH_TO_ME="${BASH_SOURCE[0]}"
##パス指定する場合はこちら
STR_FILE_PATH="$STR_PATH_TO_ME"
##バージョンに入れる日付
STR_DATE_NO=$(/bin/date +'%Y%m%d')
##ATTRの名前 配列で渡す
LIST_ATTR_NAME=(com.apple.metadata:kMDItemVersion)
##配列の処理 順番に処理する
for ITEM_ATTR_NAME in "${LIST_ATTR_NAME[@]}"
do
###現在の値
STR_PLIST_DATA=$(/usr/bin/xattr -px "$ITEM_ATTR_NAME" "$STR_FILE_PATH" |  /usr/bin/xxd -r -p | /usr/bin/plutil -convert xml1 -o - -)
###変更する値
STR_PLIST_DATA="<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><string>$STR_DATE_NO</string></plist>"
###属性を登録する
/usr/bin/xattr -w "$ITEM_ATTR_NAME" "$STR_PLIST_DATA" "$STR_FILE_PATH"
###結果
STR_PLIST_DATA=$(/usr/bin/xattr -px "$ITEM_ATTR_NAME" "$STR_FILE_PATH" |  /usr/bin/xxd -r -p | /usr/bin/plutil -convert xml1 -o - -)
/bin/echo "$STR_PLIST_DATA"
done


exit 0


|

[com.apple.metadata]bash ファイルの作成者を自分にする


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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#################################
###パス
##path to me このファイルのパス
STR_PATH_TO_ME="${BASH_SOURCE[0]}"
##パス指定する場合はこちら
STR_FILE_PATH="$STR_PATH_TO_ME"

##kMDItemAuthorsに入れるユーザー名
STR_USR_NAME=$(/usr/bin/id -F)
##ATTRの名前 配列で渡す
LIST_ATTR_NAME=(com.apple.metadata:kMDItemAuthors)
##配列の処理 順番に処理する
for ITEM_ATTR_NAME in "${LIST_ATTR_NAME[@]}"
do
###現在の値
STR_PLIST_DATA=$(/usr/bin/xattr -px "$ITEM_ATTR_NAME" "$STR_FILE_PATH" |  /usr/bin/xxd -r -p | /usr/bin/plutil -convert xml1 -o - -)

###変更する値
STR_PLIST_DATA="<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><string>$STR_USR_NAME</string></plist>"

###属性を登録する
/usr/bin/xattr -w "$ITEM_ATTR_NAME" "$STR_PLIST_DATA" "$STR_FILE_PATH"

###結果
STR_PLIST_DATA=$(/usr/bin/xattr -px "$ITEM_ATTR_NAME" "$STR_FILE_PATH" |  /usr/bin/xxd -r -p | /usr/bin/plutil -convert xml1 -o - -)
/bin/echo "$STR_PLIST_DATA"

done


exit 0


|

[SpotLight]前面FinderWIndowで拡張子検索 (SpotLightでJpgとJpegでor検索しています)


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

#!/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 framework "AppKit"
use scripting additions

property refMe : a reference to current application

##########################################
####【1】設定項目 拡張子リスト
set listExList to {"pptx", "docx", "xlsx", "pdf", "jpg", "jpeg", "png", "gif", "mp4", "mov", "mp3", "m4a", "txt", "html", "css", "js", "zip", "ai", "psd", "indd", "svg", "applescript", "scpt"} as list

##########################################
####【2】前面の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

##########################################
####【3】ダイアログ
###ダイアログを前面に出す
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
try
  set listResponse to (choose from list listExList with title "選んでください" with prompt "選んでください" default items (item 1 of listExList) 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 strExName to (item 1 of listResponse) as text
##########################################
####【4】保存先
set ocidFilePathStr to refMe's NSString's stringWithString:(strFXScopePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
set listURLvalue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLFileContentIdentifierKey) |error|:(reference))
set intScopeNo to (item 2 of listURLvalue)
set ocidFilePath to ocidFilePathURL's |path|()
###PLIST(savedSearch)保存先 ディレクトリ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
###フォルダを作る
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###Plist(savedSearch)保存パス
set strFileName to (strExName & ".savedSearch") as text

##########################################
####【5】PLIST=DICT= savedSearch新規作成
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
########ROOT
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set intValue to 1 as integer
ocidPlistDict's setValue:(intValue) forKey:"CompatibleVersion"
####JPEGとJPGを同一検索
if strExName starts with "jp" then
  set strValue to "(_kMDItemFileName = \"*.jp*\"c)" as text
else
  set strValue to "(_kMDItemFileName = \"*." & strExName & "\"c)" as text
end if
ocidPlistDict's setValue:(strValue) forKey:"RawQuery"
########RawQueryDict
set ocidRawQueryDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set booleValue to true as boolean
ocidRawQueryDict's setValue:(booleValue) forKey:"FinderFilesOnly"
set booleValue to false as boolean
ocidRawQueryDict's setValue:(booleValue) forKey:"UserFilesOnly"
####JPEGとJPGを同一検索
if strExName starts with "jp" then
  set strValue to "(_kMDItemFileName = \"*.jp*\"c)" as text
else
  set strValue to "(_kMDItemFileName = \"*." & strExName & "\"c)" as text
end if
ocidRawQueryDict's setValue:(strValue) forKey:"RawQuery"
set setObject to {ocidFilePath} as list
set arrayObject to {setObject} as list
ocidRawQueryDict's setObject:(arrayObject) forKey:"SearchScopes"
#
ocidPlistDict's setObject:(ocidRawQueryDict) forKey:"RawQueryDict"
########SearchCriteria
set ocidSearchCriteriaDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidSearchCriteriaDict's setValue:(intScopeNo) forKey:"FXScope"
set listValue to {ocidFilePath, "kMDQueryScopeNetworkIndexed"} as list
ocidSearchCriteriaDict's setObject:(listValue) forKey:"FXScopeArrayOfPaths"
set listValue to {ocidFilePath} as list
ocidSearchCriteriaDict's setObject:(listValue) forKey:"CurrentFolderPath"
set ocidFXCriteriaSlicesDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set listValue to {"com_apple_FileExtensionAttribute", 1900, 1901} as list
ocidFXCriteriaSlicesDict's setObject:(listValue) forKey:"criteria"
####JPEGとJPGを同一検索
if strExName starts with "jp" then
  set listValue to {"File Extension", "contains", "jp"} as list
else
  set listValue to {"File Extension", "is", strExName} as list
end if
ocidFXCriteriaSlicesDict's setObject:(listValue) forKey:"displayValues"
set intValue to 0 as integer
ocidFXCriteriaSlicesDict's setValue:(intValue) forKey:"rowType"
set listValue to {} as list
ocidFXCriteriaSlicesDict's setObject:(listValue) forKey:"subrows"
set listValue to {ocidFXCriteriaSlicesDict} as list
ocidSearchCriteriaDict's setObject:(listValue) forKey:"FXCriteriaSlices"
#
ocidPlistDict's setObject:(ocidSearchCriteriaDict) forKey:"SearchCriteria"
########SuggestedAttributes
set listValue to {} as list
ocidPlistDict's setObject:(listValue) forKey:"SuggestedAttributes"
########ViewSettings
set ocidViewSettingsDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set booleValue to true as boolean
ocidViewSettingsDict's setValue:(booleValue) forKey:"ContainerShowSidebar"
set booleValue to true as boolean
ocidViewSettingsDict's setValue:(booleValue) forKey:"ShowSidebar"
set booleValue to true as boolean
ocidViewSettingsDict's setValue:(booleValue) forKey:"ShowStatusBar"
set booleValue to true as boolean
ocidViewSettingsDict's setValue:(booleValue) forKey:"ShowTabView"
set booleValue to true as boolean
ocidViewSettingsDict's setValue:(booleValue) forKey:"ShowToolbar"
set recordValue to {WindowState:ocidViewSettingsDict} as record
ocidPlistDict's setObject:(recordValue) forKey:"ViewSettings"


##########################################
####【6】PLISTに変換 (optionは 0-2 Immutable /MutableContainers /MutableContainersAndLeaves)
set ocidFromat to refMe's NSPropertyListXMLFormat_v1_0
set listPlistEditDataArray to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFromat) options:0 |error|:(reference)
set ocidPlistEditData to item 1 of listPlistEditDataArray

##########################################
####【7】保存
set boolWritetoUrlArray to ocidPlistEditData's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference)

##########################################
####【8】場所を示す savedSearchファイルをFinderで開く
set ocidSharedWorkSpace to refMe's NSWorkspace's sharedWorkspace()

set strUTI to "com.apple.finder"
set ocidAppBundle to refMe's NSBundle's bundleWithIdentifier:(strUTI)
###FinderのURL
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:{ocidSaveFilePathURL} withApplicationAtURL:(ocidAppBundlePathURL) configuration:(ocidConfig) completionHandler:(missing value)

return "終了"


|

[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


|

[mdimport]Spotlightリセット(要管理者権限)

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

#!/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.6"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application


set appFileManager to refMe's NSFileManager's defaultManager()


do shell script "/usr/bin/sudo mdutil -i off -E" with administrator privileges
do shell script "/usr/bin/sudo mdutil -E /" with administrator privileges
do shell script "/usr/bin/sudo mdutil -i on /" with administrator privileges


##########################################
####### mdimporterへのパスリストを作成
##########################################
####ライブラリーのURL
set ocidLibraryURLArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSAllDomainsMask))
####戻り値格納用の可変リスト
set ocidURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
####ライブラリの数だけ繰り返し
repeat with itemLibraryURLArray in ocidLibraryURLArray
  ####Spotlightのディレクトリ
  set ocidSpotlightDirURL to (itemLibraryURLArray's URLByAppendingPathComponent:"Spotlight" isDirectory:true)
  ####mdimporterへのパスを取得
  set listContentsArray to (appFileManager's contentsOfDirectoryAtURL:ocidSpotlightDirURL includingPropertiesForKeys:{refMe's NSURLPathKey} options:(refMe's NSDirectoryEnumerationSkipsHiddenFiles) |error|:(reference))
  set ocidContentsArray to item 1 of listContentsArray
  if ocidContentsArray is not (missing value) then
    ####格納する
    (ocidURLArray's addObjectsFromArray:ocidContentsArray)
  end if
end repeat
##########################################
####### コマンド実行
##########################################
repeat with itemURLArray in ocidURLArray
  ##UNIXパスにして
  set ocidFilePath to itemURLArray's |path|()
  set strFilePath to ocidFilePath as text
  ###コマンド実行
  set strCommandText to "/usr/bin/mdimport -r \"" & strFilePath & "\"" as text
  do shell script strCommandText
end repeat

##########################################
####### オプション
##########################################
###アウトルック
set ocidAppBundle to refMe's NSBundle's bundleWithIdentifier:"com.microsoft.Outlook"
if ocidAppBundle is not (missing value) then
  set ocidAppBundlePath to ocidAppBundle's bundlePath()
  set ocidFilePath to ocidAppBundlePath's stringByStandardizingPath
  set ocidFilePathArray to ocidFilePath's stringsByAppendingPaths:{"Contents/Library/Spotlight/Microsoft Outlook Spotlight Importer.mdimporter"}
  set strFilePath to (ocidFilePathArray's objectAtIndex:0) as text
  ###コマンド実行
  set strCommandText to "/usr/bin/mdimport -r \"" & strFilePath & "\"" as text
  do shell script strCommandText
else
  set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()
  set ocidAppBundlePathURL to appNSWorkspace's URLForApplicationWithBundleIdentifier:"com.microsoft.Outlook"
  set ocidSpotlightDirURL to (ocidAppBundlePathURL's URLByAppendingPathComponent:"Contents/Library/Spotlight/Microsoft Outlook Spotlight Importer.mdimporter" isDirectory:true)
  set strFilePath to ocidSpotlightDirURL's |path|() as text
  ###コマンド実行
  set strCommandText to "/usr/bin/mdimport -r \"" & strFilePath & "\"" as text
  do shell script strCommandText
end if

###スクリプトデバッガー
set ocidAppBundle to refMe's NSBundle's bundleWithIdentifier:"com.latenightsw.ScriptDebugger8"
if ocidAppBundle is not (missing value) then
  set ocidAppBundlePath to ocidAppBundle's bundlePath()
  set ocidFilePath to ocidAppBundlePath's stringByStandardizingPath
  set ocidFilePathArray to ocidFilePath's stringsByAppendingPaths:{"Contents/Library/Spotlight/SDImporter.mdimporter"}
  set strFilePath to (ocidFilePathArray's objectAtIndex:0) as text
  ###コマンド実行
  set strCommandText to "/usr/bin/mdimport -r \"" & strFilePath & "\"" as text
  do shell script strCommandText
else
  set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()
  set ocidAppBundlePathURL to appNSWorkspace's URLForApplicationWithBundleIdentifier:"com.latenightsw.ScriptDebugger8"
  set ocidSpotlightDirURL to (ocidAppBundlePathURL's URLByAppendingPathComponent:"Contents/Library/Spotlight/SDImporter.mdimporter" isDirectory:true)
  set strFilePath to ocidSpotlightDirURL's |path|() as text
  ###コマンド実行
  set strCommandText to "/usr/bin/mdimport -r \"" & strFilePath & "\"" as text
  do shell script strCommandText
end if

##########################################
####### メールデータのインデックス
##########################################
do shell script "/usr/bin/mdimport -i $HOME/Library/Group\\ Containers/UBF8T346G9.Office/Outlook"

do shell script "/usr/bin/mdimport -i $HOME/Library/Mail"

###インポートポイントはあとはお好みで





return

|

[mdimport]インストール済みのmdimporterを読み込む(全ドメイン)

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

#!/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.6"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application


set appFileManager to refMe's NSFileManager's defaultManager()

##########################################
####### mdimporterへのパスリストを作成
##########################################
####ライブラリーのURL
set ocidLibraryURLArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSAllDomainsMask))
####戻り値格納用の可変リスト
set ocidURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
####ライブラリの数だけ繰り返し
repeat with itemLibraryURLArray in ocidLibraryURLArray
  ####Spotlightのディレクトリ
  set ocidSpotlightDirURL to (itemLibraryURLArray's URLByAppendingPathComponent:"Spotlight" isDirectory:true)
  ####mdimporterへのパスを取得
  set listContentsArray to (appFileManager's contentsOfDirectoryAtURL:ocidSpotlightDirURL includingPropertiesForKeys:{refMe's NSURLPathKey} options:(refMe's NSDirectoryEnumerationSkipsHiddenFiles) |error|:(reference))
  set ocidContentsArray to item 1 of listContentsArray
  if ocidContentsArray is not (missing value) then
    ####格納する
    (ocidURLArray's addObjectsFromArray:ocidContentsArray)
  end if
end repeat
##########################################
####### コマンド実行
##########################################
repeat with itemURLArray in ocidURLArray
  ##UNIXパスにして
  set ocidFilePath to itemURLArray's |path|()
  set strFilePath to ocidFilePath as text
  ###コマンド実行
  set strCommandText to "/usr/bin/mdimport -r \"" & strFilePath & "\"" as text
  do shell script strCommandText
end repeat

|

[検索]ペーストボードの内容をNSWorkspaceで検索

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

#!/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.6"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

###クリップボードの内容をテキストで取得
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidReadPasteboard to appPasteboard's stringForType:(refMe's NSPasteboardTypeString)
####検索
set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()
appNSWorkspace's showSearchResultsForQueryString:ocidReadPasteboard



#!/bin/bash
osascript <<-EndOfScript
use AppleScript version "2.4"
use framework "Foundation"
use framework "AppKit"
use scripting additions
set theQuery to the clipboard as text
current application's NSWorkspace's sharedWorkspace()'s showSearchResultsForQueryString:theQuery
EndOfScript

|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ 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 Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes 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 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 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 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 Plist System Events 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 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 SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design 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