Writing Maintainable Scripts
Choose the Right Language
Most scripts should be written in Bash or AppleScript as these come pre-installed on macOS.
- The task requires features unavailable in Bash/AppleScript
- The complexity justifies the additional dependency
- The functionality provides significant value to users
- Bash (recommended for system tasks)
- AppleScript (recommended for app automation)
- Swift (requires compilation)
- Node.js (requires installation)
- Python (usually pre-installed, but version may vary)
Use Proper File Naming
Always use lowercased, dash-case format with appropriate extensions:Structure Your Code Clearly
Dependency Management
Minimize Dependencies
Before adding a dependency, ask:- Can I achieve this with built-in Unix tools? (curl, awk, sed, grep, etc.)
- Is this a “deep” dependency (hides complex functionality) or “shallow” (minimal value)?
- What are the security implications?
- How many transitive dependencies will this pull in?
Examples: Built-in vs. Dependencies
JSON parsing - jq vs. built-in tools
JSON parsing - jq vs. built-in tools
With dependency (jq):Without dependency (built-in):For simple parsing, built-in tools work fine. For complex JSON manipulation,
jq is justified.HTTP requests - specialized tools vs. curl
HTTP requests - specialized tools vs. curl
Avoid: Installing a Node.js HTTP library for a simple GET requestPrefer: Using curl which is pre-installed:
Properly Declare Dependencies
If a dependency is truly necessary:Performance Optimization
Choose the Right Output Mode
The output mode affects how your script executes and displays results:silent
Best for: Instant actionsExample: Toggle system settingsPerformance: Fastest - closes immediately
compact
Best for: Long-running tasksExample: Network requests, file processingPerformance: Shows progress, last line displayed
fullOutput
Best for: Detailed outputExample: Log viewing, data displayPerformance: Can handle any output size
inline
Best for: Dashboard widgetsExample: Weather, system statsPerformance: Runs on schedule (min 10s intervals)
Optimize Long-Running Tasks
Example problem:Minimize External Calls
Reduce the number of external process calls:Security Considerations
Handling Sensitive Data
For templates requiring configuration:Use Password Arguments for Secrets
For scripts that accept sensitive input, use password-type arguments:Input Validation
Always validate user input to prevent injection attacks:Quote Variables
Always quote variables to prevent word splitting and glob expansion issues.
Error Handling
Proper Exit Codes
Raycast interprets non-zero exit codes as failures:User-Friendly Error Messages
Forcompact and inline modes, the last line of output is shown as the error message:
Graceful Degradation
Testing Your Scripts
Use ShellCheck
For Bash scripts, run ShellCheck to catch common issues:
Test in Raycast
Add your script directory to Raycast and test all scenarios:
- Normal execution
- Error conditions
- Edge cases (empty input, special characters, etc.)
Accessibility and User Experience
Choose Appropriate Icons
Use clear, recognizable icons:You can also use image files (PNG/JPEG) or URLs for icons. Keep them small (recommended 64px).
Write Clear Titles
Follow Apple’s Human Interface Guidelines for title casing:Use Descriptive Package Names
Code Quality Checklist
Before submitting your Script Command:- Uses lowercased, dash-case naming
- Includes all required metadata
- Has clear, title-cased command name
- Documents any dependencies with installation instructions
- Checks for missing dependencies before execution
- Uses appropriate output mode
- Handles errors gracefully with helpful messages
- Quotes all variables properly
- Validates user input when applicable
- Tested with ShellCheck (for Bash scripts)
- Tested in Raycast successfully
- Follows American English spelling
- No hardcoded credentials or sensitive data
- Uses built-in tools when possible
- Includes helpful comments
- Organized in appropriate directory structure

