I had Claude help me write an AppleScript and prepare this blog post. The AppleScript helps solve the problem of counting posts in categories on my Micro.Blog.

Mars Edit Post Category Counter AppleScript

This AppleScript is designed for bloggers and writers who use Mars Edit and want to quickly analyze the categories of their selected blog posts. The script provides a simple way to count how many posts are in specific categories without manual tallying. Before running the script, you'll need to:

  • Have Mars Edit installed on your Mac
  • Select the posts you want to analyze in the Mars Edit interface
  • Ensure your posts have categories named exactly "Birds" and "Books" (or modify the script for your specific categories)
  • Have AppleScript enabled on your system

The Script

-- Mars Edit Post Category Counter
-- Counts selected posts in Birds and Books categories

tell application "MarsEdit"
    -- Initialize counters
    set totalSelectedPosts to 0
    set birdsPosts to 0
    set booksPosts to 0
    
    -- Get the selected posts
    set selectedPosts to selected posts
    
    -- Count total selected posts
    set totalSelectedPosts to count of selectedPosts
    
    -- Iterate through selected posts and count categories
    repeat with thisPost in selectedPosts
        set postCategories to category names of thisPost
        
        -- Check and count Birds category
        if "Birds" is in postCategories then
            set birdsPosts to birdsPosts + 1
        end if
        
        -- Check and count Books category
        if "Books" is in postCategories then
            set booksPosts to booksPosts + 1
        end if
    end repeat
    
    -- Prepare report text
    set reportText to "Category Count Report:" & return & return & ¬
        "Total Selected Posts: " & totalSelectedPosts & return & ¬
        "Posts in Birds Category: " & birdsPosts & return & ¬
        "Posts in Books Category: " & booksPosts & return & return & ¬
        "Note: This report has been copied to the Clipboard."
    
    -- Display results in a dialog
    display dialog reportText buttons {"OK"} with icon note
    
    -- Copy report to clipboard
    set the clipboard to reportText
end tell

How to Use

  1. Open Mars Edit
  2. Select the posts you want to analyze
  3. Run the AppleScript
  4. A dialog will appear showing the category counts
  5. The report will be automatically copied to your clipboard

Note: You may need to modify the category names in the script to match your specific blog categories.