Skip to content

Commit

Permalink
added some KM stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-funderburg committed Aug 29, 2020
1 parent a552400 commit 63bb077
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 14 deletions.
32 changes: 19 additions & 13 deletions BetterTouchTool/get-git-status.applescript
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use kl : script "Kevin's Library"
property lastpath : missing value
property branch : missing value
property shellPath : "~/github/AppleScripts/BetterTouchTool/getGitBranch.sh"
property pythonpath : "~/Dropbox/Code/python/getGitStatus/getGitStatus.py"
property charlimit : 20

property symbolsTrig : missing value
Expand All @@ -22,7 +23,8 @@ tell application "Finder"
end tell
end tell

set newname to makeNewName(currentPath)
--set newname to makeNewName(currentPath)
set newname to do shell script "python3 " & pythonpath & " -n \"" & currentPath & "\""

log "INFO: lastpath: " & lastpath
log "INFO: currentpath: " & currentPath
Expand All @@ -45,24 +47,27 @@ end if

set lastpath to currentPath

if currentPath contains "Users/kevinfunderburg/Library" then
if currentPath contains "Users/kevinfunderburg/Library" or ¬
currentPath starts with "/Volumes" then
hideSymbolsTrig()
return branch
end if

set gitStatus to do shell script "sh " & shellPath & space & quoted form of currentPath

if gitStatus "false" then
set statSymbols to getStatusSymbols(gitStatus)

--set statSymbols to getStatusSymbols(gitStatus)
set branch to do shell script "cd " & quoted form of currentPath & "; git rev-parse --abbrev-ref HEAD"
set statSymbols to do shell script "python3 " & pythonpath & " -p \"" & currentPath & "\""

tell symbolsTrig
rename(statSymbols)
_font()'s setColor("red")
button()'s setColor("black")
button()'s setVisible(true)
update()
end tell

else
hideSymbolsTrig()
end if
Expand All @@ -71,18 +76,18 @@ return branch


on getStatusSymbols(gitStatus)

set branch to paragraph 1 of gitStatus
set stream to paragraph 2 of gitStatus

set statSymbols to ""

if stream = "ahead" then
set statSymbols to ""
else if stream = "behind" then
set statSymbols to ""
end if

if (count of paragraphs of gitStatus) > 2 then
set hash to {m:0, R:0, d:0, u:0}
repeat with p in (paragraphs 3 thru -1 of gitStatus)
Expand All @@ -96,13 +101,13 @@ on getStatusSymbols(gitStatus)
if hash's R 0 then set statSymbols to statSymbols & "»"
if hash's u 0 then set statSymbols to statSymbols & "?"
end if

if statSymbols "" then set statSymbols to "[" & statSymbols & "]"

set lastStatSymbols to statSymbols

return statSymbols

end getStatusSymbols

on makeNewName(_path)
Expand Down Expand Up @@ -146,3 +151,4 @@ on hideSymbolsTrig()
end tell
set branch to ""
end hideSymbolsTrig

4 changes: 4 additions & 0 deletions Keyboard-Maestro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Scripts for use while working in [Keyboard Maestro][kmapp].
- [Go To Executed Macro][8f04478c]&emsp;<kbd>⌘</kbd><kbd>⌥</kbd><kbd>G</kbd>
- Jump to the macro being called within a macro by the `Execute Macro` action.
- [Recursively Get Every Action][jf9jsn87]
- This is a useful subroutine to get _every_ action of the front macro, even those nested within if/else statements, switch statements, groups, etc.
- [Renumber Macro Number Prefix][7037aad4]&emsp;<kbd>⌘</kbd><kbd>⌃</kbd><kbd>3</kbd>
- Batch rename macros to give them ordered number prefixes, or clear the prefixes altogether.
![demo](../imgs/km-renumbermacros.gif)
Expand All @@ -60,5 +63,6 @@ Scripts for use while working in [Keyboard Maestro][kmapp].
[2f47df90]: ./Edit-Last-Executed-Macro.applescript
[bca5fefd]: ./Edit-Macro-Group-of-Front-App.applescript
[8f04478c]: ./Go-To-Executed-Macro.applescript
[jf9jsn87]: ./Recursively-Get-Every-Action.applescript
[7037aad4]: ./Renumber-Macro-Prefix-Numbers.applescript
[a0794034]: ./Collapse-All-[Pause|Type|Execute-Macro]-Actions.applescript
63 changes: 63 additions & 0 deletions Keyboard-Maestro/Recursively-Get-Every-Action.applescript
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
-- this subroutine will get every action of the front macro, even those nested
-- within control statements and groups

global allActions
set allActions to {}
tell application "Keyboard Maestro"
set m to first macro whose selected is true
my getAllActions(m's actions)
end tell

on getAllActions(actionList)
local actionList
tell application "Keyboard Maestro"
get class of actionList
if (class of actionList = list or ¬
class of actionList = action list) and ¬
(count of items of actionList) > 0 then

repeat with act in actionList
my getAllActions(act)
end repeat

else if class of actionList = case entry then

if (count of actionList's actions) > 0 then
my getAllActions(actionList's actions)
end if

else if class of actionList = action then

--set end of allActions to actionList
set end of allActions to a reference to contents of actionList

-- groups
try
if (count of actionList's actions) > 0 then
my getAllActions(actionList's actions)
end if
end try
-- switch statements
try
if (count of actionList's case entries) > 0 then
my getAllActions(actionList's case entries)
end if
end try
--if then actions
try
if actionList's thenactions missing value then
my getAllActions(actionList's thenactions's actions)
end if
end try
-- if else actions
try
if actionList's elseactions missing value then
my getAllActions(actionList's elseactions's actions)
end if
end try

end if

end tell
end getAllActions

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ Application | Scripts
<i></i> | [Edit Last Executed Macro][8265051f] | :earth_americas: | <kbd>⌃</kbd><kbd>⇧</kbd><kbd>E</kbd>
<i></i> | [Edit Macro Group of Front App][bca5fefd] | :earth_americas: | <kbd>⌘</kbd><kbd>⌥</kbd><kbd>K</kbd>
<i></i> | [Go To Executed Macro][4355277b] | <i></i> | <kbd>⌘</kbd><kbd>⌥</kbd><kbd>G</kbd>
<i></i> | [Run Current Macro][8cbb891d] | :earth_americas: | <kbd>⌘</kbd><kbd>⌃</kbd><kbd>R</kbd>
<i></i> | [Recursively Get Every Action][jf9jsn87] | <i></i> | <i></i>
<i></i> | [Renumber Macro Prefix Numbers][7037aad4] | :camera: | <kbd>⌘</kbd><kbd>⌃</kbd><kbd>3</kbd>
<i></i> | [Run Current Macro][8cbb891d] | :earth_americas: | <kbd>⌘</kbd><kbd>⌃</kbd><kbd>R</kbd>
<i></i> | <i></i> | <i></i> | <i></i>
**[Mail][mail]** | [Set Color of Text][d1529523] | :cinema: :camera: | <kbd>⌘</kbd><kbd>⇧</kbd><kbd>(C)olor</kbd>
<i></i> | [Make Mail URL][63ba2f90] | <i></i> | <kbd>⌃</kbd><kbd>U</kbd>
Expand Down Expand Up @@ -141,6 +142,7 @@ Application | Scripts
[8265051f]: ./Keyboard-Maestro/Edit-Last-Executed-Macro.applescript
[bca5fefd]: ./Keyboard-Maestro/Edit-Macro-Group-of-Front-App.applescript
[4355277b]: ./Keyboard-Maestro/Go-To-Executed-Macro.applescript
[jf9jsn87]: ./Keyboard-Maestro/Recursively-Get-Every-Action.applescript
[7037aad4]: ./Keyboard-Maestro/Renumber-Macro-Prefix-Numbers.applescript
[8cbb891d]: ./Keyboard-Maestro/Run-Current-Macro.applescript
[mail]: ./Mail
Expand Down

0 comments on commit 63bb077

Please sign in to comment.