« [LSSharedFileList]RecentHostsとRecentServerの設定 | トップページ | [LSSharedFileList]『最近使った項目』をリセットする(途中) »

[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


|

« [LSSharedFileList]RecentHostsとRecentServerの設定 | トップページ | [LSSharedFileList]『最近使った項目』をリセットする(途中) »

XML savedSearch」カテゴリの記事