« [System Events]appearance preferenc | トップページ | [System Events]マイクのボリューム »

[Terminal]選択中のディレクトリで開く

#!/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

######ログ表示
doLogView()

property objMe : a reference to current application


###選択中のエイリアスリストを取得
tell application "Finder"
set listSelectionFilePath to selection as list
end tell
####ターミナルを起動しておく
tell application "Terminal"
launch
activate
end tell

####取得数分繰り返し
repeat with objFilePath in listSelectionFilePath
####エイリアス確定
set aliasFirstFilePath to objFilePath as alias
set objInfo to info for aliasFirstFilePath
###パス先の種類を調べて
set objKind to kind of objInfo
log objKind
log class of objKind
###フォルダでなければ
if objKind is not "フォルダ" then
tell application "Finder"
###ファイルのあるディレクトリに変更
set aliasContainDir to container of aliasFirstFilePath as alias
end tell
###UNIXパス形式をクオトで挟んで取得
set strFilePaht to (quoted form of POSIX path of aliasContainDir) as text
else
#####種類がフォルダならそのまま
###UNIXパス形式をクオトで挟んで取得
set strFilePaht to (quoted form of POSIX path of aliasFirstFilePath) as text
log strFilePaht
end if
tell application "Terminal"
activate
set objWindowID to (do script "\n\n")
delay 1
###コマンド整形
set strCommandText to ("cd " & strFilePaht & "") as text
###コマンド実行
do script strCommandText in objWindowID
delay 1
### working directoryを確認
set strCommandText to ("pwd") as text
do script strCommandText in objWindowID
end tell

end repeat







#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat

end doLogView
#########################

|

« [System Events]appearance preferenc | トップページ | [System Events]マイクのボリューム »

Terminal」カテゴリの記事