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.

Linux
Migrate WordPress site to another hosting service.

IntroductionThis article details the migration of WordPress site (exactly this site you are now on) from one service provider to Amazon Lightsail. There might be various reason to do that (mine is outlined below) but in general I hope to share the message that especially with WordPress, migration can be …

Free(BSD)
Convert pdf file to jpeg – with imagemagic

Short article just to write down not-so frequently (for me) task: remove /opt/homebrew/bin from that command where using on other system than macOs Options: cheers

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, …