Skip to content

Instantly share code, notes, and snippets.

@ty0x2333
Last active May 26, 2017 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ty0x2333/5714014bb3622143c89a69dea7a1f092 to your computer and use it in GitHub Desktop.
Save ty0x2333/5714014bb3622143c89a69dea7a1f092 to your computer and use it in GitHub Desktop.
-- CLIDemo.scpt
--
-- https://gist.github.com/luckytianyiyan/5714014bb3622143c89a69dea7a1f092
--
-- The MIT License (MIT)
--
-- Copyright (c) 2017 luckytianyiyan
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
--
set currentPath to getCurrentPath() as alias
activateiTerms()
# iTerm window title
setWindowTitle("CLI Demo")
# ------- Replace Me -------
clear()
runCommand("ttyrec recording")
delay 0.5
typingString("echo Hello World
")
delay 2
runCommand("exit")
delay 0.5
runCommand("ttygif recording -f")
# ------- Replace Me End -------
# ------- Core -------
on typingString(content)
typingStringWithDelay(content, 0.1)
end typingString
on typingStringWithDelay(content, dy)
tell application "iTerm"
tell current session of current window
set charList to (characters 1 thru (length of content) of content)
repeat with char in charList
write text char newline no
delay dy
end repeat
end tell
end tell
end typingStringWithDelay
on runCommand(command)
tell application "iTerm"
tell current session of current window
write text command
end tell
end tell
end runCommand
on clear()
runCommand("clear")
delay 0.1
end clear
on isAppRunning(appName)
tell application "System Events" to (name of processes) contains appName
end isAppRunning
on setWindowTitle(title)
runCommand("echo -e \"\\033];" & title & "\\007\"")
end setWindowTitle
on activateiTerms()
if isAppRunning("iTerm") then
tell application "iTerm"
activate
end tell
else
activate application "iTerm"
end if
end activateiTerms
on getCurrentPath()
tell application "Finder"
return container of (path to me)
end tell
end getCurrentPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment