0

我正在尝试为键盘大师宏编写 AppleScript,它在现有的 Finder 窗口中打开相机 SD 或 CF 卡的图片文件夹。这是我当前的代码,它打开已安装的卷。

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)进行检查?

4

1 回答 1

0

我建议你寻找 shell 命令:system_profiler SPStorageDataType 你可以在你的 applescript 的“do shell script”命令中使用它。此命令为您提供所有连接的存储类型(USD、SD 卡、硬盘驱动器)的名称、安装点(例如 /volumes/myDisk)、物理驱动器设备名称和介质名称以及协议(USB、 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)
于 2017-09-21T16:20:50.573 回答