Last active
February 4, 2023 18:31
-
-
Save roshanca/4118971 to your computer and use it in GitHub Desktop.
Octopus: Workflow of creating a new post || previewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global projectDir | |
set homePath to POSIX path of (path to home folder) | |
set projectDir to homePath & "Ruby_app/Blog" | |
on goToProjectDir() | |
return "cd " & projectDir | |
end goToProjectDir | |
on serveWithJekyll() | |
return "bundle exec jekyll serve --watch" | |
end serveWithJekyll | |
on commandLine(currentTab) | |
tell application "Terminal" | |
do script my goToProjectDir() in currentTab | |
do script my serveWithJekyll() in currentTab | |
end tell | |
end commandLine | |
on preview() | |
delay 3 | |
tell application "Google Chrome" | |
set myTab to make new tab at end of tabs of window 1 | |
set URL of myTab to "http://localhost:4000" | |
activate | |
end tell | |
end preview | |
on newTerminalTab() | |
tell application "Terminal" to activate | |
tell application "System Events" to tell process "Terminal" to keystroke "t" using command down | |
end newTerminalTab | |
on newTerminalWindow() | |
tell application "Terminal" to activate | |
tell application "System Events" to tell process "Terminal" to keystroke "n" using command down | |
end newTerminalWindow | |
tell application "Terminal" | |
if (count of windows) is 0 then | |
my newTerminalWindow() | |
end if | |
activate | |
delay 1 | |
set currentTab to selected tab of front window | |
if currentTab is not busy then | |
my commandLine(currentTab) | |
else | |
my newTerminalTab() | |
set currentTab to selected tab of front window | |
my commandLine(currentTab) | |
end if | |
my preview() | |
end tell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "Finder" | |
activate | |
display dialog "填入文章标题" default answer "title" | |
set postTitle to text returned of result as text | |
end tell | |
tell application "Terminal" | |
activate | |
if (count of windows) is 0 then | |
tell application "System Events" | |
keystroke "n" using {command down} | |
end tell | |
else | |
activate | |
end if | |
repeat with win in windows | |
try | |
if get frontmost of win is true then | |
set currentTab to selected tab of win | |
if currentTab is not busy then | |
do script "cd ~/Ruby_app/blog" in currentTab | |
do script "rake new_post['" & postTitle & "']" in currentTab | |
delay 1 | |
set post to getRecentFileName() of postHandle | |
do script "subl source/_posts/" & post in currentTab | |
end if | |
end if | |
end try | |
end repeat | |
end tell | |
script postHandle | |
on getRecentFileName() | |
tell application "Finder" | |
set thePath to alias ((path to home folder as text) & "Ruby_app:blog:source:_posts:") | |
set fileList to files in thePath | |
set fileList to sort fileList by modification date | |
set fileName to name of first item in fileList | |
return fileName | |
end tell | |
end getRecentFileName | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment