« [mdimport]インストール済みのmdimporterを読み込む(全ドメイン) | トップページ | [UTI]アプリケーションのインストールパス »

[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を読み込む(全ドメイン) | トップページ | [UTI]アプリケーションのインストールパス »

AppleScript Spotlight」カテゴリの記事

Admin Maintenance」カテゴリの記事