You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Autosave with Date/Time as Filename

I'm on OS 13.7 and Pages 14.1...trying to create a template that autosaves new files with the date/time of creation as the filename, e.g., "YYYYMMDD-HHMM.pages". ChatGPT 4o suggests this Automator workflow, but I don't see the "Save as…" or "Save Pages Document" options. Any help appreciated. Thanks


Steps to create an automated save process in Automator:

  1. Open Automator:
    • Go to your Applications folder and open Automator.
  1. Create a New Workflow:
    • Select New Document and choose Workflow.
  1. Add the Save Action:
    • In the search bar, search for "Get Current Date" and drag that into the workflow.
    • Next, search for "Save as…" or "Save Pages Document" and drag it below the "Get Current Date" action.
  1. Set Up the File Name with Date and Time:
    • You can customize the save name by combining the current date with any text you prefer.
    • For example, the workflow could save your Pages document as something like “Document-YYYYMMDD-HHMM.pages.”
  1. Save the Workflow:
    • Once set up, save this workflow, and it can be run manually or automated further with specific triggers if needed.


iMac 27″ 5K, macOS 13.7

Posted on Oct 11, 2024 4:02 PM

Reply
2 replies

Oct 12, 2024 7:25 AM in response to mdelange

You can forget about ChatGPT writing code or Automator workflows for you.


Only Pages can create new documents from its templates, and save them. That means you would need a Run AppleScript Automator action that communicates with Pages using Pages-specific AppleScript scripting dictionary reserved words.


Here is an example Automator workflow that uses the UNIX strftime codes to format a date string as YYYYmmdd-HHMM that would be appended as a filename string component.


Then, it prompts you for the base filename (e.g. foo). The script assumes this will be written to the Desktop. Other filesystem locations would require more advanced code to prompt you for the destination folder.


Next, it launches the Pages application, and using the constructed output filename, it makes a new blank file based on the "Blank" template and then saves that file.


The only action you need in an Automator workflow is a Utilities Library > Run AppleScript. You select and replace the boilerplate text in that action and replace it with the following code that has been tested with Automator (as an application) on macOS Sequoia v15.0.1. It should work fine on Ventura 13.7. Once you have copied/pasted the following code into the Run AppleScript action, click the hammer icon to compile it.


use scripting additions

on run {input, parameters}
	
	-- YYYYmmdd-hhmm where %H is 24-hour time (0 - 23) or %I is 12-hour time
	-- if this is run more than once per minute, then you will produce the same
	-- document with a -n appended to it. To avoid that duplication issue, one
	-- can add seconds to the dateFMT as "+-%Y%m%d-%H%M%S"
	

set dateFMT to "+-%Y%m%d-%H%M"

	
	set dateStr to (do shell script "date -j " & dateFMT) as text
	try
		set thisDoc to text returned of (display dialog "Enter basename of Pages document:" default answer "") as text
	on error
		return
	end try
	if thisDoc = "" then return
	
	set newDoc to (path to desktop as text) & thisDoc & dateStr & ".pages"
	
	tell application "Pages" to if it is running then quit
	delay 1
	
	tell application "Pages"
		launch
		set newFile to (make new document with properties {name:newDoc, document template:template "Blank"})
		with timeout of 60 seconds
			close newFile saving yes saving in file newDoc
		end timeout
	end tell
	
	tell application "Pages" to if it is running then quit
	
	-- by default Pages hides the filename extension in the Finder
	-- this will reveal it
	tell application "Finder"
		if exists (newDoc) then
			set extension hidden of (item newDoc as alias) to false
		else
			return
		end if
	end tell
	return
	
end run


When it prompts me for a filename, I enter foo, and the foo-20241012-1019.pages document is written to the Desktop.




Autosave with Date/Time as Filename

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.