2
votes

Firstly, let me stress that I have almost no Applescript experience. I'm an Oracle developer by trade, so please assume my knowledge is ZERO so I'd be grateful if you could really dumb down your response.

I wrote this script a year or so ago and it has suddenly stopped working. I'm guessing that a macOS upgrade (on High Sierra) no longer tolerates my probably poorly written script.

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

The error I get is "The action "Run AppleScript" encountered an error: "Finder got an error: Can't set file "Macintosh HD:Users:Karla:Pictures:1-IMAGES-TO-DO:image1-lg.jpg" to 2."

If I comment out the tagging and try to just do the move, I get "The action "Run AppleScript" encountered an error: "Finder got an error: Can't get folder "Mackintosh HD:Users:Karla:Pictures:FTP:main-[lg]:"."

Edit:

I have also tried:

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

but get the error The action "Run AppleScript" encountered the error: "Can't get POSIX file (alias "Macintosh HD:Users:Karla:Pictures:file.jpg")."

Edit again:

So this is where I am. I've created a droplet as follows:

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

And I still get a -1728 error onthe file. "Can’t get file (alias \"Macintosh HD:Users:Karla:Pictures:test1:test-lg.jpg\")." number -1728 from file (alias "Macintosh HD:Users:Karla:Pictures:test1:test-lg.jpg")

I've spent 2 days on a script that used to work and now inexplicably does not in amongst trying to do my real job. This is supposed to make my life easier.

2
output a filepathPat_Morita
did you try it with a Posix path instead of hfs? "/Users/Karla/..." instead of "Macintosh HD:Users:Karla:..." to transform hfs to posix use "posix path of someHFSPath"Pat_Morita
Yes. Perhaps if someone could explain why my script no longer works, I would know where to start looking. I'm not the only one with this problem: stackoverflow.com/questions/6250691/…KJordan

2 Answers

1
votes

Try using this code for your droplet...

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
0
votes

If anybody comes here as I did, looking for an answer, I can give you an inelegant, hacky way to at least get this working. I had variable this_item which contained an HFS file which I wanted to move into todaysFolder.

Part of the problem is Finder doesn't always know what to do with POSIX paths involving variables, and sometimes you need to use the "my" keyword first. Other time, you need to leave it out. I couldn't figure out the logic.

The following ridiculous code block does it reliably and seems to catch every strange, inscrutable exception.

         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