![]() ![]()
What I thought was probably going to be a trivial shell script quickly became something more complicated, but not so much so that it was beyond reach. The ‘Move Last Downloaded File Here’ Keyboard Maestro macro is then set up like this. Keyboard maestro create folder with variables download#Notify "Error, Exit Code: $mvStatus " "Move Last Download Here" "Glass" fi Notify "File Moved: $lastDownloadFile " "Move Last Download Here" "Tink" else Keyboard maestro create folder with variables code#aiff" } # Set-up variables lastDownloadFile = $( ls -pAt $HOME/Downloads | grep -v '/$' | head -n 1 ) lastDownloadPath = $HOME/Downloads/ $lastDownloadFile finderCurrentFolder = $(osascript -e "tell application \" Finder \" to get the POSIX path of the (insertion location as text)" ) destinationPath = $finderCurrentFolder$lastDownloadFile # Output paths to standard out in case we need to debug echo FROM: $lastDownloadPath echo TO: $destinationPath # Move the file mv " $lastDownloadPath " " $destinationPath " # Check the exit code and notify accordingly mvStatus = $( echo $? ) echo Exit Code: $mvStatus if then Osascript -e 'display notification "' $1 '" with title "' $2 '"'Īfplay "/System/Library/Sounds/ $3. ![]() #!/bin/zsh # Generate a visual and auditory notification function notify ![]() The script then displays a visual notification appropriate to what happened, and I play a different sound depending upon whether the move completed successfully or not. Instead I returned to the shell script and added an additional check for the exit code of the file move. However, I decided that this was a poor choice, because it was not telling me if my move had completed successfully. The shell script is executed via an Execute Shell Script action, and I originally added a Play Sound action as a notification to let me know when the move has completed. I simply created a new hot key triggered macro to a Keyboard Maestro group I have set up to only be accessible when Finder is the active app. I have several of ways I could do assign it to a keyboard shortcut (wrap it in an AppleScript for FastScripts, add it as a script to Better Touch Tool or Alfred, create an Automator/Shortcuts quick action), but I opted for my standard tool for running these sorts of things - Keyboard Maestro. Keyboard maestro create folder with variables windows#While I could in effect run this from anywhere, I can have multiple Finder windows and tabs open, and to make sure that I am 100% clear on where files are being moved to, I decided to tie this to Finder and access it as a keyboard shortcut. #!/bin/zsh # Set-up variables lastDownloadFile = $( ls -pAt $HOME/Downloads | grep -v '/$' | head -n 1 ) lastDownloadPath = $HOME/Downloads/ $lastDownloadFile finderCurrentFolder = $(osascript -e "tell application \" Finder \" to get the POSIX path of the (insertion location as text)" ) destinationPath = $finderCurrentFolder$lastDownloadFile # Output paths to standard out in case we need to debug echo FROM: $lastDownloadPath echo TO: $destinationPath # Move the file mv " $lastDownloadPath " " $destinationPath " Triggering the Script The basic operation can be expressed with a single move command, where I need to get the path of the last downloaded file ( $lastDownloadPath), and build a path for the destination based on the current location in Finder. So, it seemed like this was the obvious way to tackle this issue, but the scripting turned out to be a little more convoluted than I first imagined. It is pretty much what shell scripting was invented for. Shell scripts are ideal for moving files around. Recently I realised I was missing this functionality over on my Mac, and so I decided to redress the imbalance through a little scripting. ![]() I have written about a very similar XYplorer script in the past that works in the same way, but rather than the last download, it grabs a copy of the last screenshot I took. One of my most used extensions is one which will move the last downloaded file to the directory in the currently focused XYplorer pane. In my day job, I work on Windows, and XYplorer is my file manager of choice due to it’s configurability and extensibility through scripting. Move Last Download to Current Finder Folder ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |