tell application "Keyboard Maestro Engine"
set sourceFolder to getvariable "CurrentSongAssetsPath01"
end tell
tell application "Finder"
move POSIX file "/Users/dannywyatt/My Files/Inbox Global/images/Facebook-Feed.png" to folder sourceFolder with replacing
end tell
The path is this (coming from the global variable CurrentSongAssetsPath01
/Users/dannywyatt/My Files/Music Projects/Danny Wyatt/Music/_Assets Promo Videos/Danny Wyatt - Bond
I get this error: Execute an AppleScript failed with script error: text-script:138:258: execution error: Finder got an error: Can’t get folder "/Users/dannywyatt/My Files/Music Projects/Danny Wyatt/Music/_Assets Promo Videos/Danny Wyatt - Bond". (-1728). Macro “move images test” cancelled (while executing Execute AppleScript).
I will see if I can do it. This post is familiar, meaning I think I had to achieve this recently, but I can't seem to find where I took notes about this.
tell application "Keyboard Maestro Engine"
set KMvar to getvariable "CurrentSongAssetsPath01"
end tell
set destFolder to alias POSIX file KMvar
tell application "Finder"
move POSIX file "/Users/dannywyatt/My Files/Inbox Global/images/Facebook-Feed.png" to folder destFolder with replacing
end tell
I tried editing the last line to this, but no difference
move POSIX file "/Users/dannywyatt/My Files/Inbox Global/images/Facebook-Feed.png" to destFolder
Hmm. I think this should work. Are you sure you have the path right?
Try to verify by pasting "/Users/dannywyatt/My Files/Music Projects/Danny Wyatt/Music/_Assets Promo Videos/Danny Wyatt - Bond" into an If action with "At this path: something exists" condition:
My bad...
I was performing some tests using that path, then I was working on something else, ended up deleting that folder, but didn't notice that the script was using that old path.
Thanks for pointing that out. I guess I'm just tired after spending the whole day creating macros haha
One question, if you know how to do this:
So this is the script
tell application "Keyboard Maestro Engine"
set KMvar1 to getvariable "CurrentSongAssetsPath01"
set slugDashes to getvariable "new365SongPhotoshopExportTriggerDashes"
end tell
set destFolder to alias POSIX file KMvar1
tell application "Finder"
move POSIX file "/Users/dannywyatt/My Files/Music Projects/Danny Wyatt/Music/_Assets Promo Videos/_All Images/Facebook-Feed.png" to folder destFolder
end tell
Right before the file name (Facebook-Feed.png), I would like to add a variable (slugDashes).
I was checking this page and I think I did everything right:
But when I run it I get this: 2023-11-20 22:01:20 Action 15400890 failed: Execute an AppleScript failed with script error: text-script:248:418: execution error: Finder got an error: Can’t get POSIX file "/Users/dannywyatt/My Files/Music Projects/Danny Wyatt/Music/_Assets Promo Videos/_All Images/bond-Facebook-Feed.png". (-1728) 2023-11-20 22:01:20 Execute an AppleScript failed with script error: text-script:248:418: execution error: Finder got an error: Can’t get POSIX file "/Users/dannywyatt/My Files/Music Projects/Danny Wyatt/Music/_Assets Promo Videos/_All Images/bond-Facebook-Feed.png". (-1728). Macro “5 - move images test” cancelled (while executing Execute AppleScript).
But this time, the path is good, because I copied from the Engine Log and compared it with the file's path, copied from finder:
I definitely do not know the "right" way to do this with AppleScript, and I would probably manipulate path stuff in KM before passing it if I could, but try to build the string for the file path first, like this:
set SourceString to "/Users/dannywyatt/My Files/Music Projects/Danny Wyatt/Music/_Assets Promo Videos/_All Images/" & slugdashes & "-Facebook-Feed.png"
set SourceFile to POSIX file SourceString
tell application "Finder"
move SourceFile to folder destFolder with replacing
end tell
Thank you so much Evan! That worked like a charm!
Yes, a good alternative would be to define all variables, including the the "slugs" variable and just send the final one to AS.
The reason I'm using AS is because sometimes creating a macro using actions takes longer and it gets messy really fast. I've been experiencing that in the last few days and I would like to start using AS sometimes for certain scenarios where I can create a good workflow in a few seconds.
I will save this solution on my Notes so I can go back to it next time I need it.
The "with replacing" part is just necessary if there are files with the same name, right? I removed it, because I'm 100% sure I will never have 2 files there with the same name.
FWIW, I use Script Debugger to fiddle with these things before dropping them into KM. Here's what it said in the dictionary for the "with replacing" parameter of the move command: "Specifies whether or not to replace items in the destination that have the same name as items being moved"
I have it installed, but I'm very new to AppleScript so having a more advanced tool like that doesn't give me much insight, because it kinda confuses me even more haha
I'm learning as I go, taking notes, saving some scripts as a reference, etc