By Alvin Alexander. Last updated: May 19, 2018
AppleScript subroutine FAQ: How do I create an AppleScript subroutine (or AppleScript function)?
Creating a subroutine in AppleScript is pretty easy. Jumping right in, here's an example of an AppleScript subroutine that adds one to whatever you pass into it:
-- a super-simple subroutine on addOne(a) return a + 1 end addOne -- test the subroutine set answer to addOne(50) display dialog answer
I create lots of little AppleScript subroutines to modularize my code, and I encourage you to do the same. Every subroutine should do one (and only one) thing, and do it well.