Dynamically Change Screenshot Save Location (based on time/front app)

The title essentially says it all. Let’s say I’m using messages and want to clip part of the conversation, is there any way for me to have kbm either change the default screenshot save location (ex. /pictures/screenshots/messages) the moment I enter messages, or have it automatically move the screenshot file after I take it?

Working with this, can I have it further refine the save location based on if/then statements (I can do time of day calculations to put in the parameters I want), or is there even a simpler way to do it?

Any help is appreciated, thanks

To hopefully save some time, I’ve already tried having it run the “defaults write com.apple.screencapture location” script triggered by application launch/activation and quit/deactivation, but this hasn’t proven to be reliable, plus it’s hardly ideal because you have to restart SystemUIServer for it to take effect. My menu bar doesn’t need to flash from the SystemUIServer restart every time I switch apps.

See this macro. It is not exactly what you are asking for, but should give you a good basis to build what you want.

BTW, I easily found this macro, by clicking on the "screenshot" tag at the top of this page.

This macro does exactly that. It sets the preferences for the default location.
It also remembers your last locations, so you can easily toggle between different ones.

If you want a couple of features more (select location, set name, set properties, post-process screenshot), try that one:

I should have checked this before finding a longer way to do it on my own. I also should have checked the tags, sorry. They're new since my last visit here, so I didn't think of it even when clicking them to include on my own post.

Right now I have a method reliant upon running the "defaults write com.apple.screencapture "include-date" 0" script to remove the date in screenshots, as well as a folder in ~/Pictures labeled "Screenshots". It'll work until I go through and hopefully pull from the other macros shared to move the screenshots without needing the names to be "Screen Shot", "Screen Shot (2)", etc.

The macro will sort into folders based on application, and then within those folders will create subfolders for each display connected, provided the Screenshots folder in ~/Pictures exists. (Ex. ~/Pictures/Screenshots/Safari/Display 1, Display 2, Display 3). The screenshots are also renamed based on the application taken in, time taken, and display. (Ex. Keyboard Maestro (1) at Sep 10, 2016, 08.54.37 PM.png). I have it set for up to three displays, but if someone smarter than I am wants to make it work automatically for however many displays someone wants to connect, they're welcome to it.

  1. To use this, default screencapture location must be your desktop

  2. You'll have to run the "defaults write com.apple.screencapture "include-date" 0" script to exclude date and time from screenshot names

  3. You'll have to have a folder in ~/Pictures titled "Screenshots"

  4. Your default screen capture key will have to be cmd+shift+3 (if you want to change it for cmd+shift+4 it's easy enough though, and then you don't even need the parts of the macro that deal with more than one display).

  5. Finally, and this one will be a real pain, you'll have to go through the whole macro and change the paths from my username to yours. (if someone knows how to get around this, please tell me because I'll be sending this macro to some friends)

What I'd love to improve and is probably possible:

  • Having to remove screenshot date from default files (this is especially a pain when kbm engine isn't running and files therefore aren't renamed including the date).

  • Everyone I send this to having to change my username to theirs time after time after time.

  • Automatically creating aliases for each screenshot within a different file system for a variety of sorting and organization methods that people might want to use

  • What I'd love to improve and is probably impossible:

  • Automatically deleting screenshots of secondary displays when there's nothing on them.

  • Naming screenshots of secondary displays to the app actually displayed on them, instead of the current foremost app.

I think I'm done for the night, but I'll probably take a swing at some of this tomorrow. If anyone who knows how to do it would be willing to steer me in the right direction or even put it right into the macro I would be forever grateful. Screenshot Organizer.kmmacros (12.9 KB)

To give some answers:

You'll have to have a folder in ~/Pictures titled "Screenshots"

You can create folders from within a KM macro. Search the forum how to do.

Finally, and this one will be a real pain, you'll have to go through the whole macro and change the paths from my username to yours.

Use ~ instead of /Users/XXX. Should work with most actions; if it doesn’t work feed the path to a variable and filter it with “expanding ~ in path”

You'll have to run the "defaults write com.apple.screencapture "include-date" 0" script to exclude date and time from screenshot names
[…]
Having to remove screenshot date from default files (this is especially a pain when kbm engine isn't running and files therefore aren't renamed including the date).

If you set the screenshot defaults with defaults write the setting is permanent. You can also include the defaults write script in your macro. (Execute Shell Script action.)

You can read the settings with defaults read, for example:

Maybe there are some more (unset) options, but I don’t think so.

Independent of that, why are you quitting KM Engine?

Automatically creating aliases for each screenshot within a different file system for a variety of sorting and organization methods that people might want to use

Not sure if I understand. But Aliases (Mac Finder Aliases) only work with the HFS+ file system. If you copy folder structures containing Aliases to another file system (e.g. FAT on an USB stick) the Aliases won’t work there.

I already have the macro making folders, this was just for anyone wanting to try it. I had a folder in that location that I used already, but not everyone will.

Went through and did this; it still works. Thanks!

Thanks, I didn't want to include it in the macro so it wouldn't change settings automatically whenever someone wanted to use it. What I'd really like to do is find some way to still move and rename the screenshots even when they include the date information at the end of them. I think one of the macros posted on this thread has what I'm looking for, but I don't understand it enough to incorporate it yet.

It's a pretty rare thing, but from time to time I'll be low enough on battery and far enough from an outlet that the extra few minutes I get from stopping the engine is worth it.

Yes, the aliases would just be another way of organizing the screenshots on the mac itself, without taking up the space that duplicates would. For example, if I wanted to have the screenshots automatically saved in an organized way, but still have a folder with a dump of aliases for every screenshot that I could put in my dock for easy access.

Thanks for helping me out!

The Macro so far.

The Create Folder action will not always succeed. See here or a couple of other posts for details.

What I'd really like to do is find some way to still move and rename the screenshots even when they include the date information at the end of them.

Not sure what you mean. If the date information (as part of the file name) is subject to change, then you must exclude it when selecting the files to move by name. For example you can test for files whose basename begins with “Screen Shot” and whose extension is “png”, or whatever.

Yes, I have a lot of if/then statements about whether a folder already exists, etc, so the whole path will be built by the macro, if needed.

Ahh, I didn't know you could exclude parts of the file name. Is this simple enough to do?

I don’t know what’s “simple” for you :wink: Try it, if you get stuck look up in the KM Wiki or post the problem here.

In your screenshot above I’m only seeing files that get moved and renamed by appending a date. So I guess you’re talking about something that’s not in the image. And without knowing the concrete task it’s a bit difficult to help.

The whole macro is in that image, so it should be there. What I’m try to talk about is the ability to move and rename files even if they don’t have the same name.

For example, by default screenshots are saved with a name something like “Screen Shot 2016-08-26 at 2.14.02 PM.png”. Because I changed the defaults, my screenshots save as just “Screen Shot” until moved and renamed by km. What I’d eventually like to get is some method of working with the default filename for screenshots.

OK, I understand now.

Try this:

__Tmp.kmmacros (3.7 KB)

You have to replace the folder names with ones that exist on your Mac.

  1. Start the macro.
  2. The macro looks for files (in a given folder) whose basename contains “screen shot” and whose extension is “png”.
  3. If it finds any it moves them to a destination folder and adds a suffix “my-new-suffix”.

Edit: Corrected the description.

Thank you! I’ll try putting that in and see what happens.