{"id":1285,"date":"2023-04-14T02:28:09","date_gmt":"2023-04-14T09:28:09","guid":{"rendered":"https:\/\/www.useriscontent.com\/blog\/?p=1285"},"modified":"2023-05-13T16:47:19","modified_gmt":"2023-05-13T23:47:19","slug":"converting-old-macwrite-files-to-libreoffice-using-automator","status":"publish","type":"post","link":"https:\/\/www.useriscontent.com\/blog\/2023\/04\/14\/converting-old-macwrite-files-to-libreoffice-using-automator\/","title":{"rendered":"Converting Old MacWrite Files to LibreOffice Using Automator"},"content":{"rendered":"<p>Found a cache of old MacWrite files (they appear in Finder as a black exec<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-1286\" src=\"https:\/\/www.useriscontent.com\/blog\/..\/media\/exec-150x150.jpeg\" alt=\"\" width=\"150\" height=\"150\" \/>icon). At least I think they're MacWrite files. They retain the creation dates which are around 1998.<br \/>\nThey will open up quite well and retain most of the formatting with LibreOffice. But I was wanting to batch convert them using\u00a0 Automator. Eventually I asked my new friend Chat who was able to help me out. After a few iterations we found something that works like a charm.<\/p>\n<p><a href=\"https:\/\/www.useriscontent.com\/blog\/..\/media\/libreAutomatorApp-1.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1288 size-full\" src=\"https:\/\/www.useriscontent.com\/blog\/..\/media\/libreAutomatorApp-1.jpeg\" alt=\"\" width=\"764\" height=\"326\" srcset=\"https:\/\/www.useriscontent.com\/blog\/..\/media\/libreAutomatorApp-1.jpeg 764w, https:\/\/www.useriscontent.com\/blog\/..\/media\/libreAutomatorApp-1-650x277.jpeg 650w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a>The code in the shell script is (can't vouch for the indentation):<code><\/code><\/p>\n<pre>for f in \"$@\"\r\ndo\r\n    input_dir=$(dirname \"$f\")\r\n    input_filename=$(basename \"$f\")\r\n    output_filename=\"${input_filename%.*}.odt\"\r\n    \/Applications\/LibreOffice.app\/Contents\/MacOS\/soffice --convert-to odt --outdir \"$input_dir\" \"$f\" --headless\r\n    mv \"$input_dir\/$output_filename\" \"$input_dir\/$input_filename.odt\"\r\ndone<\/pre>\n<p>And if you'd care to see the explanation, here's the full convo with Chat. What was very cool was figuring out how to make the converted file save into the same directory the original was in.<\/p>\n<p>This script will:<\/p>\n<ul>\n<li>Get the input file directory and filename using the <code>dirname<\/code> and <code>basename<\/code> commands.<\/li>\n<li>Set the output filename to be the input filename with the <code>.odt<\/code> extension using the <code>${input_filename%.*}<\/code> syntax.<\/li>\n<li>Use LibreOffice to convert the input file to ODT and save it in the input file directory using the <code>--outdir<\/code> option.<\/li>\n<li>Rename the converted ODT file to have the same name as the input file with the <code>.odt<\/code> extension.Save the Automator workflow.<\/li>\n<\/ul>\n<p>Now when you run the Automator app and drop MacWrite files onto it, the converted ODT files will be saved in the same directory as the original files with the same filename but with the <code>.odt<\/code> extension.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Found a cache of old MacWrite files (they appear in Finder as a black exec icon). At least I think they're MacWrite files. They retain the creation dates which are around 1998. They will open up quite well and retain most of the formatting with LibreOffice. But I was wanting to batch convert them using\u00a0 &hellip; <a href=\"https:\/\/www.useriscontent.com\/blog\/2023\/04\/14\/converting-old-macwrite-files-to-libreoffice-using-automator\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> \"Converting Old MacWrite Files to LibreOffice Using Automator\"<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[437,435,436,434],"class_list":["post-1285","post","type-post","status-publish","format-standard","hentry","category-from-the-field","tag-automator","tag-batch-convert","tag-libreoffice","tag-macwrite"],"_links":{"self":[{"href":"https:\/\/www.useriscontent.com\/blog\/wp-json\/wp\/v2\/posts\/1285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.useriscontent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.useriscontent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.useriscontent.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.useriscontent.com\/blog\/wp-json\/wp\/v2\/comments?post=1285"}],"version-history":[{"count":10,"href":"https:\/\/www.useriscontent.com\/blog\/wp-json\/wp\/v2\/posts\/1285\/revisions"}],"predecessor-version":[{"id":1305,"href":"https:\/\/www.useriscontent.com\/blog\/wp-json\/wp\/v2\/posts\/1285\/revisions\/1305"}],"wp:attachment":[{"href":"https:\/\/www.useriscontent.com\/blog\/wp-json\/wp\/v2\/media?parent=1285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.useriscontent.com\/blog\/wp-json\/wp\/v2\/categories?post=1285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.useriscontent.com\/blog\/wp-json\/wp\/v2\/tags?post=1285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}