Skip to content

Instantly share code, notes, and snippets.

@peerasak-u
Created October 3, 2023 17:25
Show Gist options
  • Save peerasak-u/2d708b166c0c9bf605c9badcbd5dede2 to your computer and use it in GitHub Desktop.
Save peerasak-u/2d708b166c0c9bf605c9badcbd5dede2 to your computer and use it in GitHub Desktop.

πŸš€ Xcode Lazy Coder Service πŸ›Œ

A macOS service for those Xcode wizards πŸ§™ who sometimes just want to take the easy road. Generates a quirky formatted string with your file name and selected code, copies it straight to your clipboard, and magically opens a specified website.✨

🌈 Features

  • πŸ“œ Formatted String Generation: Pops out a string like:
    ARE YOU LAZY?
    FILENAME:  {{FILE_NAME_FROM_XCODE}}
    SOURCECODE: 
    {{SELECTED_CODE}}
    
  • πŸ“‹ Copy to Clipboard: Whoosh! Your text is now on the clipboard.
  • 🌐 Open Website: Auto-surfing to https://lazy.peerasak.com.

πŸ›  Setup

1️⃣ Creating the Automator Service

  1. Launch Automator on your beloved Mac.
  2. Choose File > New and pick Quick Action.
  3. Top right corner: Make sure it receives selected text from our friend, Xcode.
  4. Search (left bar) for our handy tool Run AppleScript and drag it over.

2️⃣ The Magic Script

Paste this magical incantation into the Run AppleScript box:

on run {input, parameters}
    -- Seek the name of the current file in Xcode
    set fileName to ""
    tell application "Xcode"
        set fileName to name of the first source document
    end tell
    
    if fileName is "" then
        set fileName to "UNKNOWN FILE"
    end if

    set output to "ARE YOU LAZY?" & linefeed & "FILENAME:  \"" & fileName & "\"" & linefeed & "SOURCECODE: " & linefeed & input
    return output
end run

3️⃣ Clipboard & Surfing πŸ„

  1. Post-AppleScript, look for Copy to Clipboard and drag below.
  2. Find Run Shell Script, drag below Copy to Clipboard and use this to ride the web waves:
open "https://lazy.peerasak.com"

4️⃣ Save and Unleash the Magic

  1. Stash the Automator service with a catchy name like "Lazy Coder Extravaganza".
  2. Fire up Xcode, snag some text in any file.
  3. Right-click, sail to Services, and there you'll spot "Lazy Coder Extravaganza". Give it a tap.

πŸŽ‰ Party Time

All set! Whenever you're in Xcode, and the laziness beckons, just snatch your source code, right-click, and hit "Lazy Coder Extravaganza" from Services. Your zany text is now on the clipboard, and you're surfing the web. Enjoy the ride! 🎒

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment