How do you change the format of the OSX Screen Shot file name?

I'd like my screen shots to only be named with the current date time, preferably in a format like:

2016-09-02-16:02:48

How should I go about doing this?

So far I've tried inserting an empty string into com.apple.screencapture name

as shown:

$ defaults write com.apple.screencapture name ""
$ killall SystemUIServer

But OSX is still inserting a space as shown below: enter image description here

So there's two problems I'm having:

  1. How do I change the date time format so there are no spaces?
  2. How do I make sure there is no leading space in the screenshot filename?

Thanks :)


You neither can rename a file to the proposed name - it contains several colons (:) which are reserved (= forbidden) characters in the HFS+ file system - nor does defaults write com.apple.screencapture ... allow a different date format.

One idea though is creating a launch agent to rename all files in a dedicated folder starting with "Screen Shot ...":

A very simple solution, assuming you restore the default naming convention for screenshots and replace user_name by your short name below, is then:

Create a file named "screencaprn" in e.g /usr/local/bin with the content:

#!/bin/bash

mv /Users/user_name/Desktop/Screen\ Shot*.png /Users/user_name/Desktop/"`date "+%Y-%m-%d-%H.%M.%S"`.png"; $2>/dev/null

Change permissions:

chmod +x /usr/local/bin/screencaprn

Then create a launch agent in ~/Library/LaunchAgents with the name "usr.screenshot.rename.plist" and the content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>usr.screenshot.rename</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
        <string>-c</string>
        <string>/usr/local/bin/screencaprn</string>
    </array>
    <key>WatchPaths</key>
    <array>
        <string>/Users/user_name/Desktop</string>
    </array>
</dict>
</plist>

Then load the plist with:

launchctl load ~/Library/LaunchAgents/usr.screenshot.rename.plist

This works but has a delay of up to 10 seconds (thus changes the seconds and sometimes the minutes of the original named screenshot file e.g. Screen Shot 2016-09-03 at 03.24.02.png to 2016-09-03-03.24.05.png) and adds one com.apple.xpc.launchd[1] (usr.screenshot.rename): Service only ran for X seconds. Pushing respawn out by Y seconds. line to the system log.


The time format is based on what you have in:
System Preferences > Language & Region > 24-Hour Time

It can be overridden by changing the format in:
System Preferences > Language & Region > Advanced... > Times > Medium

There is an odd bug in Finder when renaming screenshots that do not have the AM/PM in the filename, as the periods separating the time are confused with the one separating the file extensions.

To get rid of the Screen shot and leading space, I'd use a tool that watches the filesystem and can carry out user-defined actions — something like Hazel. In fact, you could not mess with System Preferences at all and just get Hazel to rename the screen shot files for you.

Note: you won't be able to use the : colon character in filenames.


j̶u̶s̶t̶ ̶u̶s̶e̶ ̶2̶ ̶c̶o̶m̶m̶a̶n̶d̶s̶:̶ ̶

d̶e̶f̶a̶u̶l̶t̶s̶ ̶w̶r̶i̶t̶e̶ ̶c̶o̶m̶.̶a̶p̶p̶l̶e̶.̶s̶c̶r̶e̶e̶n̶c̶a̶p̶t̶u̶r̶e̶ ̶n̶a̶m̶e̶ ̶"̶$̶(̶d̶a̶t̶e̶ ̶+̶%̶Y̶-̶%̶m̶-̶%̶d̶)̶ ̶$̶(̶d̶a̶t̶e̶ ̶+̶%̶H̶-̶%̶M̶-̶%̶S̶)̶"̶ 
defaults write com.apple.screencapture "include-date" 0

Please note that you can't use the : in filenames on macos.

I̶ ̶u̶s̶e̶ ̶2̶ ̶d̶a̶t̶e̶ ̶v̶a̶r̶i̶a̶b̶l̶e̶s̶ ̶t̶o̶ ̶a̶c̶h̶i̶e̶v̶e̶ ̶t̶h̶i̶s̶ ̶t̶e̶m̶p̶l̶a̶t̶e̶:̶ ̶̶2̶0̶1̶9̶-̶0̶7̶-̶0̶2̶ ̶2̶3̶-̶0̶4̶-̶0̶4̶.̶p̶n̶g̶̶

you can also change the default screenshot location (in my case this is a folder in iCloud)

defaults write com.apple.screencapture location "~/Library/Mobile\ Documents/com\~apple\~CloudDocs/screenshots"

UPD: its not correct solution. the name will be the same for each screenshot, and generated date - its the date when you run these command