0

I have to make an export from a banking app and I like to move the generated file, which is located somewhere deep inside of /tmp/..., to a folder inside documents.

tell application "MoneyMoney"
    set exportFile to export transactions from account "DE91787695590008764648" from date "2022-01-01" to date "2022-12-31" as "csv"
end tell

tell application "Finder"
    set fileName to name of (POSIX file exportFile as alias)
    set targetName to "/Users/username/Documents/Klientendaten/AccountImport/" & fileName
    move exportFile as POSIX file to folder targetName as POSIX file
end tell

return targetName

The script editor tells something with Error in AppleEvent-Routine number -10000. I think it has something to do with targetName, which apple script can't find, but that definitively exists. Is there a mistake in targetName? Or is the move-call wrong?

3
  • btw: script has full disk access.
    – mihema
    Commented Aug 3, 2022 at 19:02
  • What type of value does exportFile get assigned by the "MoneyMoney" app?
    – CJK
    Commented Aug 4, 2022 at 7:57
  • It's a string containing the path to the exported file
    – mihema
    Commented Aug 4, 2022 at 9:15

1 Answer 1

0

The problem is most likely where you've defined targetName: if this is a path to a file (and not a folder), asserting it later to be a folder in the move command will not be possible; if it is a path to a folder, then it almost certainly doesn't exist as it's derived from the name of the file that is exported moments before.

Here's an amended version of the salient portion of your script:

set targetPath to "/Users/username/Documents/Klientendaten/AccountImport/"
        
tell application id "com.apple.Finder" to tell (move ¬
        (the exportFile as POSIX file) to the folder ¬
        (targetPath as POSIX file)) as text to return ¬
        the POSIX path

I've added in parentheses to aid clarity, although the way you formulated it—even without parentheses—is fine and would work just as well. This moves the exportFile to the folder AccountImport. If you actually wanted to move it to a folder with the same name as the exportFile, then this folder needs to be created first:

set targetPath to "/Users/username/Documents/Klientendaten/AccountImport/"

tell application id "com.apple.Finder" 
         set exportFile to the file named (exportFile as POSIX file)
         set targetFolder to the folder named (targetPath as POSIX file)
         set targetFolder to make new folder in the targetFolder ¬
                 with properties {name:exportFile's name as text}
         move the exportFile to the targetFolder
         return the POSIX path of (the result as text)
end tell
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .