Skip to content

Instantly share code, notes, and snippets.

@jeena
Last active March 20, 2016 08:28
Show Gist options
  • Save jeena/f881aa267f4809e3b0f0 to your computer and use it in GitHub Desktop.
Save jeena/f881aa267f4809e3b0f0 to your computer and use it in GitHub Desktop.
-- A script to select the next random Call of Duty map
repeat with usermap in shuffle(getMaps())
display dialog "Next map: " & usermap giving up after 3600 * 10
nextMap(usermap)
end repeat
on split(theString, theDelimiter)
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to theDelimiter
set theArray to every text item of theString
set AppleScript's text item delimiters to oldDelimiters
return theArray
end split
on getMaps()
set userLibPath to POSIX path of (path to library folder from user domain as string)
set usermapsPath to userLibPath & "/Application Support/Call of Duty 4/usermaps/"
set usermaps to (list folder usermapsPath without invisibles)
return usermaps
end getMaps
on shuffle(l)
set i to count of l
repeat while i ≥ 2
set j to random number from 1 to i
tell l to set {item i, item j} to {item j, item i}
set i to i - 1
end repeat
return l
end shuffle
on nextMap(usermap)
set cmd to "map " & usermap
set cmdArray to my split(cmd, "")
tell application "Call of Duty 4 Multiplayer" to activate
tell application "System Events" to keystroke "`"
repeat with char in cmdArray
tell application "System Events" to keystroke char
end repeat
tell application "System Events" to keystroke return
end nextMap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment