【问题标题】:"Tag and move" Applescript no longer works (High Sierra)“标记和移动”Applescript 不再有效 (High Sierra)
【发布时间】:2021-02-17 20:15:35
【问题描述】:

首先,让我强调一下,我几乎没有 Applescript 经验。我是一名 Oracle 开发人员,所以请假设我的知识是零,所以如果你能真正愚蠢地回答,我将不胜感激。

我大约一年前写了这个脚本,但它突然停止工作了。我猜 macOS 升级(在 High Sierra 上)不再容忍我可能写得不好的脚本。

on run {input, parameters}

repeat with theFile in input

    set FileName to theFile as text
    tell application "Finder"
        if FileName ends with "-xs.jpg" then
            --label value, 0 is no label, 1 Orange, 2 Red, 6 Geen
            set the label index of file FileName to 6
            move FileName to folder "Macintosh HD:Users:Karla:Pictures:FTP:basket-[xs]:" with replacing

        else if FileName ends with "-sm.jpg" then
            set the label index of file FileName to 1
            move FileName to folder "Macintosh HD:Users:Karla:Pictures:FTP:thumbnails-[sm]:" with replacing

        else if FileName ends with "-lg.jpg" then
            set the label index of file FileName to 2
            move FileName to folder "Macintosh HD:Users:Karla:Pictures:FTP:main-[lg]:" with replacing

        else if FileName ends with "-xlg.jpg" then
            set the label index of file FileName to 5
            move FileName to folder "Macintosh HD:Users:Karla:Pictures:FTP:large-[xlg]:" with replacing

        end if
    end tell
end repeat
return input
end run

我得到的错误是“操作“运行 AppleScript”遇到错误:“Finder 出错:无法设置文件”Macintosh HD:Users:Karla:Pictures:1-IMAGES-TO-DO:image1- lg.jpg" 到 2."

如果我注释掉标记并尝试只是移动,我得到“操作“运行 AppleScript”遇到错误:“Finder 出错:无法获取文件夹”Mackintosh HD:Users:Karla:Pictures :FTP:main-[lg]:"."

编辑:

我也试过了:

on run {input, parameters}
    repeat with the_input_file in input
        set FileName to POSIX file (the_input_file as alias)
    end repeat    
    return input
 end run

但出现错误“运行 AppleScript”操作遇到错误:“无法获取 POSIX 文件(别名“Macintosh HD:Users:Karla:Pictures:file.jpg”)。”

再次编辑:

所以这就是我所在的地方。我创建了一个液滴如下:

on open theDroppedItems
    set lg_folder to POSIX path of "Macintosh HD:Users:Karla:Pictures:test1:"
    repeat with current_item_cnt from 1 to count of theDroppedItems

    -- load the next file in the_file
    set the_current_file to item current_item_cnt of theDroppedItems
    move file the_current_file to lg_folder
end repeat
end open

我仍然在文件上收到 -1728 错误。 “无法获取文件(别名 \"Macintosh HD:Users:Karla:Pictures:test1:test-lg.jpg\")。”来自文件的编号 -1728(别名“Macintosh HD:Users:Karla:Pictures:test1:test-lg.jpg”)

我花了 2 天时间编写一个曾经可以工作的脚本,但现在却莫名其妙地无法完成我真正的工作。这应该让我的生活更轻松。

【问题讨论】:

  • 输出文件路径
  • 您尝试过使用 Posix 路径而不是 hfs 吗? "/Users/Karla/..." 而不是 "Macintosh HD:Users:Karla:..." 将 hfs 转换为 posix 使用 "posix path of someHFSPath"
  • 是的。也许如果有人可以解释为什么我的脚本不再有效,我会知道从哪里开始寻找。我不是唯一一个遇到这个问题的人:stackoverflow.com/questions/6250691/…

标签: macos applescript macos-high-sierra


【解决方案1】:

尝试将此代码用于您的液滴...

property folderXS : "Macintosh HD:Users:Karla:Pictures:FTP:basket-[xs]"
property folderSM : "Macintosh HD:Users:Karla:Pictures:FTP:thumbnails-[sm]"
property folderLG : "Macintosh HD:Users:Karla:Pictures:FTP:main-[lg]"
property folderXL : "Macintosh HD:Users:Karla:Pictures:FTP:large-[xlg]"

on run
    --  Executed when the script is launched

    set theFiles to choose file with prompt ¬
        "Choose Files" multiple selections allowed true ¬
        without showing package contents

    repeat with theFile in theFiles
        set FileName to theFile as text
        tell application "Finder"
            if FileName ends with "-xs.jpg" then
                --label value, 0 is no label, 1 Orange, 2 Red, 6 Green
                set the label index of file FileName to 6
                move FileName to folder folderXS with replacing
            else if FileName ends with "-sm.jpg" then
                set the label index of file FileName to 1
                move FileName to folder folderSM with replacing
            else if FileName ends with "-lg.jpg" then
                set the label index of file FileName to 2
                move FileName to folder folderLG with replacing
            else if FileName ends with "-xlg.jpg" then
                set the label index of file FileName to 5
                move FileName to folder folderXL with replacing
            end if
        end tell
    end repeat
    return theFiles
end run


on open theDroppedItems
--  Executed when files are dropped on the script

    set lg_folder to "Macintosh HD:Users:Karla:Pictures:test1"
    repeat with current_item_cnt from 1 to count of theDroppedItems
        set the_current_file to item current_item_cnt of theDroppedItems
        tell application "Finder"
            move file the_current_file to lg_folder
        end tell
    end repeat
end open

【讨论】:

    【解决方案2】:

    如果有人像我一样来到这里寻找答案,我可以给你一个不优雅的,hacky 的方式来至少让它工作。我有变量this_item,其中包含一个我想移入todaysFolder的HFS文件。

    部分问题在于 Finder 并不总是知道如何处理涉及变量的 POSIX 路径,有时您需要先使用“my”关键字。其他时候,您需要将其排除在外。我无法弄清楚其中的逻辑。

    以下荒谬的代码块可靠地执行此操作,并且似乎捕获了每一个奇怪的、难以理解的异常。

             try
                    
                    move my (POSIX file (POSIX path of this_item)) to folder (todaysFolder) of disk "Hard Drive" with replacing
                on error
                    try
                        move (POSIX file (POSIX path of this_item)) to folder (todaysFolder)  of disk "Hard Drive" with replacing
                    on error
                        try
                            move (file (POSIX path of this_item)) to folder (todaysFolder) of disk "Hard Drive" with replacing
                        on error
                            move (file (this_item)) to folder (todaysFolder) of disk "Hard Drive" with replacing
                        end try
                    end try
                    
                end try
                
    

    【讨论】:

      猜你喜欢
      • 2018-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      相关资源
      最近更新 更多