Create Pages document in Finder (macOS + automator)

Uncategorized

As you most probably know, in macOS you can use automation to run repeatable tasks. Automator requires little bit scripting so the task is not necessary to be done by everyone, but lots of users can find it extremely useful. In addition It is always possible to run AI to write the code skeleton and then modify it a bit according to your needs.

One of the tasks I am running quite frequently is to create new (empty) Pages document. My goal was to create script that will create document by selecting right click on Folder -> Quick Actions.

  • open automator program and choose Quick Action
  • select actions and drag/drop “Run AppleScript”
  • paste the code (below)
on run {input, parameters}
	-- Ensure only one folder is selected
	if (count of input) is not equal to 1 then return input
	
	-- Get the selected folder's path and name
	set targetFolder to item 1 of input
	set folderPath to POSIX path of targetFolder
	tell application "Finder" to set folderName to name of (targetFolder as alias)
	
	-- Specify the source template file location
	set sourceFile to (POSIX path of (path to documents folder)) & "Template.pages"
	
	-- Get the current date and format it
	set currentDate to do shell script "date +%Y-%m-%d"
	
	-- Create the destination path with the folder's name and the current date
	set destinationFile to folderPath & folderName & " " & currentDate & ".pages"
	
	-- Copy the template file to the target folder with the new name
	do shell script "cp " & quoted form of sourceFile & " " & quoted form of destinationFile
	
	return input
end run
  • set the following setting for the script
  • save the script with nice name like: “Create Pages Document from Folder Name”

In addition to that do the following two steps:

  • open Pages and create document “Template.pages” in you Documents Folder
  • add Finder to “Full Disk Access” in “System Settings -> Privacy & Security -> Full Disk Access”

    Test new function:

Script can be found: /Users/YOURUSERNAME/Library/Services

ToDo:

Fix the script to create additional with slightly different name when file (created by this automation) already exists.

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Uncategorized
Photo albums: How to deal with that beast

If you are like me, you probably have a ton of photos from your escapades, significant moments of your life. Some photos are more important, some can be deleted, some you don’t even want to see (for whatever reason). In a perfect world I would review all those photos regularly, …

Uncategorized
Export your data from iCloud (for archive and other purposes)

It is always a little bit tricky for me to find where to download all my data from iCloud in case I want to archive them at my home disk, or basically I want to remove some of my data from iCloud to avoid additional fee for cloud storage space. …

Azure
Why Firefox is important and people should use this browser in 2024, my thoughts.

Can you remember the times when everyone was using Internet Explorer? Back in the ’90s and the early part of this century, Internet Explorer dominated the browser market. Software Incompatibility with Other Browsers Incompatibility issues with software and other browsers have been a persistent problem. Even in 2022, this remains …