【问题标题】:Open an unspecifiable Folder with applescript用applescript打开一个无法指定的文件夹
【发布时间】:2018-03-02 12:14:29
【问题描述】:

我正在尝试为 Keyboard Maestro 宏编写 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)?

【问题讨论】:

    标签: automation applescript keyboard-maestro


    【解决方案1】:

    我建议你寻找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)
    

    【讨论】:

    • 感谢您的信息。但我的主要问题是我是否可以以某种方式提示 DCIM 子文件夹 xxxND800 与最高数字。
    • 对不起,我误会了。我已经用小代码更新了我的答案以获得最高的文件夹编号。只要文件夹数量合理(,性能就OK
    猜你喜欢
    • 1970-01-01
    • 2012-06-30
    • 1970-01-01
    • 2017-03-12
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多