2017-09-21 79 views
0

私はKeyboard Maestroマクロ用のAppleScriptを作成しようとしています。既存のFinderウィンドウにカメラのSDまたはCFカードの画像フォルダを開きます。 これは私の現在のコードで、マウントされたボリュームを開きます。AppleScriptで不特定のフォルダを開く

tell application "Keyboard Maestro Engine" 
    set KMVarPath to get value of variable "path" 
end tell 



set the_string to "/Volumes/" & KMVarPath 
set the_path to (POSIX file the_string) as string 

tell application "Finder" 
    activate 
    if window 1 exists then 
     set target of window 1 to the_path 
    else 
     reveal the_path 
    end if 
end tell 

問題は、これらのフォルダが276ND2XSまたは105ND800と呼ばれていることです。私は '接尾辞'(ND2XS/ND800)を指定し、最高の接頭辞番号を持つフォルダを開きたいと思います。

これを行う方法はありますか?

便宜上、ボリュームがSDカードかCFカードかを確認する方法はありますか?または名前(NIKON D2XS/NIKON D800)で確認する必要がありますか?

答えて

0

シェルコマンドを探すことをお勧めします。system_profiler SPStorageDataType あなたのリンスクリプトの "do shell script"コマンドで使うことができます。 このコマンドは、接続されているすべてのストレージタイプ(USD、SDカード、ハードドライブ)、マウントポイント(example/volumes/myDisk)、物理ドライブデバイス名とメディア名、およびプロトコル、SATA、ATA、...)。私はテストするCFカードがありませんが、それはあなたに検出する方法を与える必要があります。たとえば、SDカードを使用する場合、メディア名は「APPLE SD Card Reader Media」です。

ボリュームを知ったら、と最も高いカウンタ名でフォルダを取得することができます。詳細については、

set the_path to choose folder -- this is just for my test ! replace by your path "Volumes:..." as alias 

set the_Folder to "" 
set the_Highest to 0 
tell application "Finder" 
set my_List to name of every folder in the_path whose (name contains "D2XS") or (name contains "ND800") 
repeat with a_folder in my_List 
    try 
     set the_Num to (text 1 thru 3 of a_folder) as integer 
    on error 
     set the_Num to 0 
    end try 
    if the_Num > the_Highest then 
     set the_Highest to the_Num 
     set the_Folder to a_folder 
    end if 
end repeat 
end tell 

log "num=" & the_Num 
log "fodler=" & (the_Folder) 
+0

感謝。しかし、私の主な質問は、何とかDCIMサブフォルダxxxND800にhighes番号を付けるよう促すことができるかどうかということでした。 – payun

+0

申し訳ありませんが、私は誤解しました。最高のフォルダ番号を得るために、小さなコードで私の答えを更新しました。フォルダ数が合理的(<200)であれば、パフォーマンスは問題ありません。 – pbell

関連する問題