Create Pages document in Finder (macOS + automator)
- By : La
- Category : 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