{"id":19931,"date":"2024-11-23T17:24:01","date_gmt":"2024-11-23T17:24:01","guid":{"rendered":"https:\/\/johnjohnston.info\/blog\/?p=19931"},"modified":"2024-11-23T17:25:52","modified_gmt":"2024-11-23T17:25:52","slug":"applescript-fun-with-claude","status":"publish","type":"post","link":"https:\/\/johnjohnston.info\/blog\/applescript-fun-with-claude\/","title":{"rendered":"AppleScript Fun with Claude"},"content":{"rendered":"\n<p> I occasionally use AppleScript to avoid repetitive tasks. I quite enjoy writing scripts. My scripting tend to follow the guess and check procedure. It can be weeks or months between these efforts so I need to look up the library or search for many basic things<sup data-fn=\"1295f530-f6f1-4ae7-9715-6a6f2008ab8f\" class=\"fn\"><a href=\"#1295f530-f6f1-4ae7-9715-6a6f2008ab8f\" id=\"1295f530-f6f1-4ae7-9715-6a6f2008ab8f-link\">1<\/a><\/sup>. <\/p>\n\n\n\n<p>In my part time job, I quite often report findings or issues with the Glow Blogs system. In doing so I need to remember to include: computer model, OS version Browser and Browser version. This is quite simple but requires a few clicks and a bit of typing. I thought today I might create and AppleScript to do this for me. <\/p>\n\n\n\n<p>I then thought I might use Claude.ai to get me started<sup data-fn=\"66f6a4e8-a58c-4004-b5a4-e0d9c3e993e0\" class=\"fn\"><a href=\"#66f6a4e8-a58c-4004-b5a4-e0d9c3e993e0\" id=\"66f6a4e8-a58c-4004-b5a4-e0d9c3e993e0-link\">2<\/a><\/sup>. I used the prompt:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Can you give me a n applescript that will report on the current model of mac, the version of the OS and the current application &amp; version?<\/p>\n<\/blockquote>\n\n\n\n<p> I&#8217;ve noticed that AI doesn&#8217;t seem to be bothered with my constant typos! <\/p>\n\n\n\n<p>The first script threw an error when I tested it. So I copied the error and the line it came from and sent it back to Claude. Another error. This continued through 10 versions. Sometimes I broke off to test an idea of my own or check the AppleScript Library and reported that to Claude. <\/p>\n\n\n\n<p>This began to feel a bit like my usual process of testing, checking and reading. But a good bit quicker. We <a title=\"Claude Artifact\" href=\"https:\/\/claude.site\/artifacts\/fdb3ed30-3c6b-436a-b89e-7595b7dbe38c\">finally got there<\/a>. I just added a line to copy to the clipboard and put the script in the Script Library so I can call it with <a href=\"https:\/\/redsweater.com\/fastscripts\/\">FastScripts<\/a><sup data-fn=\"0d25938f-7ca2-451c-9d84-5840c593070c\" class=\"fn\"><a href=\"#0d25938f-7ca2-451c-9d84-5840c593070c\" id=\"0d25938f-7ca2-451c-9d84-5840c593070c-link\">3<\/a><\/sup>.<\/p>\n\n\n\n<p>For some reason I thanked Claude:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote has-background is-layout-flow wp-block-quote-is-layout-flow\" style=\"background-color:#f0f0f599\">\n<p> You&#8217;re welcome! The final script successfully gets: <\/p>\n\n\n\n<p>1. The Mac&#8217;s hardware model <\/p>\n\n\n\n<p>2. Current OS version <\/p>\n\n\n\n<p>3. Active application name and version <\/p>\n\n\n\n<p>Just for future reference &#8211; we went through several approaches before landing on the most reliable method using <code>osascript<\/code> to directly query the application&#8217;s version. This ended up being more robust than trying to get the version from file metadata or application paths. <\/p>\n\n\n\n<p>Let me know if you need any modifications or have other AppleScript questions!<\/p>\n<\/blockquote>\n\n\n\n<p>At this point I only had one free message left. So I asked Claude to refactor the script into a shell script. This it did with one error. With no more messages left, a search <a href=\"https:\/\/stackoverflow.com\/questions\/24515436\/how-to-get-current-foreground-applications-name-or-pid-in-os-x#comment138153740_24562352\">produced a fix<\/a> pretty quickly. I ended up with <a href=\"https:\/\/gist.github.com\/troutcolor\/9657199b10666f277d8b7aae662e9d79\">this<\/a>.<\/p>\n\n\n<ol class=\"wp-block-footnotes\"><li id=\"1295f530-f6f1-4ae7-9715-6a6f2008ab8f\">This is true of all the <em>scripty<\/em> type things I do. Except for HyperCard which I used every day for years.   <a href=\"#1295f530-f6f1-4ae7-9715-6a6f2008ab8f-link\" aria-label=\"Jump to footnote reference 1\">\u21a9\ufe0e<\/a><\/li><li id=\"66f6a4e8-a58c-4004-b5a4-e0d9c3e993e0\">I&#8217;ve been using free versions of AI for a while now. A few times a week. Mostly for school things. Creating a text for pupils, or questions on a text. Claude is my current fav for scripting. <a href=\"#66f6a4e8-a58c-4004-b5a4-e0d9c3e993e0-link\" aria-label=\"Jump to footnote reference 2\">\u21a9\ufe0e<\/a><\/li><li id=\"0d25938f-7ca2-451c-9d84-5840c593070c\">I think FastScript is one of my favourite mac applications. It is very handy for this sort of script as you can either select it from FastScripts menu or give it a keyboard shortcut. The Front application, which we are interested in, stays at the front. <a href=\"#0d25938f-7ca2-451c-9d84-5840c593070c-link\" aria-label=\"Jump to footnote reference 3\">\u21a9\ufe0e<\/a><\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>I occasionally use AppleScript to avoid repetitive tasks. I quite enjoy writing scripts. My scripting tend to follow the guess and check procedure. It can be weeks or months between these efforts so I need to look up the library or search for many basic things. In my part time job, I quite often report [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"mf2_syndication":["https:\/\/bsky.app\/profile\/johnjohnston.info\/post\/3lbmz4dkxbd2x","https:\/\/social.ds106.us\/@johnjohnston\/113533429450733043"],"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"webmentions_disabled_pings":false,"webmentions_disabled":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"[{\"content\":\"This is true of all the <em>scripty<\/em> type things I do. Except for HyperCard which I used every day for years.  \",\"id\":\"1295f530-f6f1-4ae7-9715-6a6f2008ab8f\"},{\"content\":\"I've been using free versions of AI for a while now. A few times a week. Mostly for school things. Creating a text for pupils, or questions on a text. Claude is my current fav for scripting.\",\"id\":\"66f6a4e8-a58c-4004-b5a4-e0d9c3e993e0\"},{\"content\":\"I think FastScript is one of my favourite mac applications. It is very handy for this sort of script as you can either select it from FastScripts menu or give it a keyboard shortcut. The Front application, which we are interested in, stays at the front.\",\"id\":\"0d25938f-7ca2-451c-9d84-5840c593070c\"}]"},"categories":[953],"tags":[957,93,1908],"post_format":[],"class_list":{"0":"post-19931","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-posse","7":"tag-ai","8":"tag-applescript","9":"tag-claude","10":"kind-article","12":"h-entry","13":"hentry"},"better_featured_image":null,"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p57zFQ-5bt","jetpack_likes_enabled":false,"jetpack_sharing_enabled":true,"kind":false,"_links":{"self":[{"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/posts\/19931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/comments?post=19931"}],"version-history":[{"count":6,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/posts\/19931\/revisions"}],"predecessor-version":[{"id":19943,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/posts\/19931\/revisions\/19943"}],"wp:attachment":[{"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/media?parent=19931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/categories?post=19931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/tags?post=19931"},{"taxonomy":"post_format","embeddable":true,"href":"https:\/\/johnjohnston.info\/blog\/wp-json\/wp\/v2\/post_format?post=19931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}