{"id":1333,"date":"2024-08-24T16:43:58","date_gmt":"2024-08-24T16:43:58","guid":{"rendered":"https:\/\/labiol.xyz\/?p=1333"},"modified":"2024-08-26T09:33:21","modified_gmt":"2024-08-26T09:33:21","slug":"create-pages-document-in-finder-macos-automator","status":"publish","type":"post","link":"https:\/\/www.labiol.xyz\/index.php\/2024\/08\/24\/create-pages-document-in-finder-macos-automator\/","title":{"rendered":"Create Pages document in Finder (macOS + automator)"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>open automator program and choose Quick Action<\/li>\n\n\n\n<li>select actions and drag\/drop &#8220;Run AppleScript&#8221;<\/li>\n\n\n\n<li>paste the code (below)<\/li>\n<\/ul>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>on run {input, parameters}\n\t-- Ensure only one folder is selected\n\tif (count of input) is not equal to 1 then return input\n\t\n\t-- Get the selected folder&#39;s path and name\n\tset targetFolder to item 1 of input\n\tset folderPath to POSIX path of targetFolder\n\ttell application &quot;Finder&quot; to set folderName to name of (targetFolder as alias)\n\t\n\t-- Specify the source template file location\n\tset sourceFile to (POSIX path of (path to documents folder)) & &quot;Template.pages&quot;\n\t\n\t-- Get the current date and format it\n\tset currentDate to do shell script &quot;date +%Y-%m-%d&quot;\n\t\n\t-- Create the destination path with the folder&#39;s name and the current date\n\tset destinationFile to folderPath & folderName & &quot; &quot; & currentDate & &quot;.pages&quot;\n\t\n\t-- Copy the template file to the target folder with the new name\n\tdo shell script &quot;cp &quot; & quoted form of sourceFile & &quot; &quot; & quoted form of destinationFile\n\t\n\treturn input\nend run<\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>set the following setting for the script<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"589\" height=\"127\" src=\"http:\/\/3.127.215.50\/wp-content\/uploads\/2024\/08\/image.png\" alt=\"\" class=\"wp-image-1337\" srcset=\"https:\/\/www.labiol.xyz\/wp-content\/uploads\/2024\/08\/image.png 589w, https:\/\/www.labiol.xyz\/wp-content\/uploads\/2024\/08\/image-300x65.png 300w\" sizes=\"auto, (max-width: 589px) 100vw, 589px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>save the script with nice name like: &#8220;Create Pages Document from Folder Name&#8221;<\/li>\n<\/ul>\n\n\n\n<p>In addition to that do the following two steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>open Pages and create document &#8220;Template.pages&#8221; in you Documents Folder<\/strong><\/li>\n\n\n\n<li><strong>add Finder to &#8220;Full Disk Access&#8221; in &#8220;System Settings -&gt; Privacy &amp; Security -&gt; Full Disk Access&#8221;<\/strong><br><br>Test new function:<br><img decoding=\"async\" src=\"http:\/\/3.127.215.50\/wp-content\/uploads\/2024\/08\/image-1.png\" alt=\"\"><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>Script can be found: \/Users\/YOURUSERNAME\/Library\/Services<\/p>\n\n\n\n<p>ToDo:<\/p>\n\n\n\n<p>Fix the script to create additional with slightly different name when file (created by this automation) already exists.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <\/p>\n","protected":false},"author":1,"featured_media":1341,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"[]"},"categories":[1],"tags":[],"class_list":["post-1333","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts\/1333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=1333"}],"version-history":[{"count":10,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts\/1333\/revisions"}],"predecessor-version":[{"id":1347,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts\/1333\/revisions\/1347"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/media\/1341"}],"wp:attachment":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=1333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=1333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=1333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}