Created
April 15, 2018 15:31
-
-
Save OKsign/43278d818079ebf3619a4bcf43750f00 to your computer and use it in GitHub Desktop.
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
<?xml version="1.0"?> | |
<root> | |
<vkopenurldef> | |
<name>KeyCode::VK_OPEN_URL_94-1-remove E line and tab</name> | |
<url type="shell"> | |
osascript -e ' | |
set sName to "94-1" | |
tell application "System Events" | |
tell process "SystemUIServer" | |
click (menu bar item 1 of menu bar 1 whose description is "AppleScript") | |
end tell | |
delay 0.2 | |
tell application "System Events" | |
keystroke sName | |
delay 0.2 | |
key code 36 | |
end tell | |
end tell | |
' | |
</url> | |
</vkopenurldef> | |
<vkopenurldef> | |
<name>KeyCode::VK_OPEN_URL_94-2-remove E line and tabEnd</name> | |
<url type="shell"> | |
osascript -e ' | |
set sName to "94-2" | |
tell application "System Events" | |
tell process "SystemUIServer" | |
click (menu bar item 1 of menu bar 1 whose description is "AppleScript") | |
end tell | |
delay 0.2 | |
tell application "System Events" | |
keystroke sName | |
delay 0.2 | |
key code 36 | |
end tell | |
end tell | |
' | |
</url> | |
</vkopenurldef> | |
<item> | |
<name>My Key 94: Remove Empty Lines and Tabs</name> | |
<item> | |
<name>Empty Lines and All Tabs_Hold T</name> | |
<identifier>Empty Lines and All Tabs_Hold T</identifier> | |
<autogen> | |
--HoldingKeyToKey-- | |
KeyCode::T, ModifierFlag::NONE, | |
@begin | |
KeyCode::T, | |
@end | |
@begin | |
<!-- run via script menu --> | |
KeyCode::VK_OPEN_URL_94-1-remove E line and tab, | |
@end | |
Option::NOREPEAT, | |
</autogen> | |
</item> | |
<item> | |
<name>Empty Lines and Tabs at The End of Line_Option + T</name> | |
<identifier>Empty Lines and Tabs at The End of Line_Option + T</identifier> | |
<autogen> | |
--KeyToKey-- | |
KeyCode::T, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_OPTION, ModifierFlag::NONE, | |
<!-- run via script menu --> | |
KeyCode::VK_OPEN_URL_94-2-remove E line and tabEnd, | |
</autogen> | |
</item> | |
</item> | |
</root> | |
<!-- script 1-Remove Empty Lines and All Tabs: | |
set oldClip to the clipboard | |
delay 0.02 | |
tell application "System Events" | |
keystroke "c" using command down | |
end tell | |
delay 0.7 | |
set copT to the clipboard | |
set AppleScript's text item delimiters to return | |
set a to every text item of copT | |
delay 0.02 | |
if (count a) = 1 then | |
if text item 1 of a contains space then | |
set AppleScript's text item delimiters to space | |
set OneLineSpace to every text item of text item 1 of a | |
set defOneLineSpace to 0 | |
repeat with p from 1 to count OneLineSpace | |
if text item p of OneLineSpace is "" then | |
set fac to 1 | |
set defOneLineSpace to defOneLineSpace + fac | |
end if | |
end repeat | |
if defOneLineSpace = (count OneLineSpace) then | |
delay 0.02 | |
tell application "System Events" | |
key code 51 | |
end tell | |
delay 0.07 | |
set the clipboard to oldClip | |
delay 0.02 | |
return | |
end if | |
end if | |
end if | |
if (count a) = 1 then | |
if text item 1 of a contains tab then | |
set AppleScript's text item delimiters to tab | |
set OneLineTab to every text item of text item 1 of a | |
set defOneLineTab to 0 | |
repeat with p from 1 to count OneLineTab | |
if text item p of OneLineTab is "" then | |
set fac to 1 | |
set defOneLineTab to defOneLineTab + fac | |
end if | |
end repeat | |
if defOneLineTab = (count OneLineTab) then | |
delay 0.02 | |
tell application "System Events" | |
key code 51 | |
end tell | |
delay 0.07 | |
set the clipboard to oldClip | |
delay 0.02 | |
return | |
end if | |
end if | |
end if | |
set ans to 0 | |
repeat with j from 1 to (count a) | |
if (text item j of a) is not "" then | |
delay 0.02 | |
set makeFirst to j | |
set y to 1 | |
set ans to ans + y | |
exit repeat | |
end if | |
end repeat | |
if ans = 0 then | |
set the clipboard to oldClip | |
return | |
end if | |
if ans is not equal to 0 then | |
set myT to text item makeFirst of copT | |
try | |
repeat with k from (makeFirst + 1) to (count a) | |
if (text item k of a) is not "" then | |
delay 0.02 | |
set myT to myT & " | |
" & (text item k of a) | |
end if | |
end repeat | |
end try | |
end if -- ans is not equal to 0 | |
set AppleScript's text item delimiters to " | |
" | |
set b to every text item of a | |
set myT2 to {} | |
set defTab to 0 | |
repeat with l from 1 to count b | |
if (text item l of b) contains tab then | |
delay 0.03 | |
set conTab to 1 | |
set defTab to defTab + conTab | |
set AppleScript's text item delimiters to "" | |
set tabFound to every text item of (text item l of b) | |
set lineTab to "" | |
repeat with i from 1 to count tabFound | |
if (item i of tabFound) is not tab then | |
delay 0.05 | |
set lineTab to lineTab & item i of tabFound | |
end if -- (item i of tabFound) is not " " | |
end repeat | |
copy lineTab to the end of myT2 | |
else | |
copy (text item l of b) to the end of myT2 | |
end if -- (text item l of b) contains tab | |
end repeat -- with l from 1 to count b | |
delay 0.02 | |
if defTab > 0 then | |
set myT3 to {} | |
repeat with u from 1 to count myT2 | |
if item u of myT2 is not "" then | |
copy item u of myT2 to the end of myT3 | |
end if | |
end repeat | |
try | |
set myT4 to item 1 of myT3 | |
repeat with u from 2 to count myT3 | |
set myT4 to myT4 & " | |
" & item u of myT3 | |
end repeat | |
set the clipboard to myT4 | |
end try | |
delay 0.02 | |
tell application "System Events" | |
keystroke "v" using command down | |
end tell | |
delay 0.5 | |
set the clipboard to oldClip | |
end if | |
if defTab = 0 then | |
set the clipboard to myT | |
delay 0.02 | |
tell application "System Events" | |
keystroke "v" using command down | |
end tell | |
delay 0.5 | |
set the clipboard to oldClip | |
end if -- noTab = 0 then | |
-- end of script 1-Remove Empty Lines and All Tabs | |
script 2-Remove Empty Lines and Tabs at the End of Line: | |
set oldClip to the clipboard | |
delay 0.02 | |
tell application "System Events" | |
keystroke "c" using command down | |
end tell | |
delay 0.7 | |
set copT to the clipboard | |
set AppleScript's text item delimiters to return | |
set a to every text item of copT | |
if (count a) = 1 then | |
if text item 1 of a contains space then | |
set AppleScript's text item delimiters to space | |
set OneLineSpace to every text item of text item 1 of a | |
set defOneLineSpace to 0 | |
repeat with p from 1 to count OneLineSpace | |
if text item p of OneLineSpace is "" then | |
set fac to 1 | |
set defOneLineSpace to defOneLineSpace + fac | |
end if | |
end repeat | |
if defOneLineSpace = (count OneLineSpace) then | |
delay 0.02 | |
tell application "System Events" | |
key code 51 | |
end tell | |
delay 0.07 | |
set the clipboard to oldClip | |
delay 0.02 | |
return | |
end if | |
end if | |
end if | |
if (count a) = 1 then | |
if text item 1 of a contains tab then | |
set AppleScript's text item delimiters to tab | |
set OneLineTab to every text item of text item 1 of a | |
set defOneLineTab to 0 | |
repeat with p from 1 to count OneLineTab | |
if text item p of OneLineTab is "" then | |
set fac to 1 | |
set defOneLineTab to defOneLineTab + fac | |
end if | |
end repeat | |
if defOneLineTab = (count OneLineTab) then | |
delay 0.02 | |
tell application "System Events" | |
key code 51 | |
end tell | |
delay 0.07 | |
set the clipboard to oldClip | |
delay 0.02 | |
return | |
end if | |
end if | |
end if | |
set ans to 0 | |
repeat with j from 1 to (count a) | |
if (text item j of a) is not "" then | |
delay 0.02 | |
set makeFirst to j | |
set y to 1 | |
set ans to ans + y | |
exit repeat | |
end if | |
end repeat | |
if ans = 0 then | |
set the clipboard to oldClip | |
return | |
end if | |
if ans is not equal to 0 then | |
set myT to text item makeFirst of copT | |
try | |
repeat with k from (makeFirst + 1) to (count a) | |
if (text item k of a) is not "" then | |
delay 0.02 | |
set myT to myT & " | |
" & (text item k of a) | |
end if | |
end repeat | |
end try | |
end if -- ans is not equal to 0 | |
set AppleScript's text item delimiters to " | |
" | |
set b to every text item of a | |
set myT2 to {} | |
set defTab to 0 | |
if ans is not equal to 0 then | |
repeat with l from 1 to count b | |
if (text item l of b) contains tab then | |
delay 0.03 | |
set conTab to 1 | |
set defTab to defTab + conTab | |
set AppleScript's text item delimiters to "" | |
set tabFound to every text item of (text item l of b) | |
repeat with i from (count tabFound) to 1 by -1 | |
if (item i of tabFound) is not " " then | |
set makeEnd to i | |
exit repeat | |
end if | |
end repeat | |
set lineTab to text item 1 of tabFound | |
try | |
repeat with Z from 2 to makeEnd | |
set lineTab to lineTab & item Z of tabFound | |
end repeat | |
end try | |
copy lineTab to the end of myT2 | |
else | |
copy (text item l of b) to the end of myT2 | |
end if -- (text item l of b) contains tab | |
end repeat -- with l from 1 to count b | |
end if | |
delay 0.02 | |
if defTab > 0 then | |
set myT3 to {} | |
repeat with u from 1 to count myT2 | |
if item u of myT2 is not "" then | |
copy item u of myT2 to the end of myT3 | |
end if | |
end repeat | |
set myT4 to item 1 of myT3 | |
repeat with u from 2 to count myT3 | |
set myT4 to myT4 & " | |
" & item u of myT3 | |
end repeat | |
set the clipboard to myT4 | |
delay 0.02 | |
tell application "System Events" | |
keystroke "v" using command down | |
end tell | |
delay 0.5 | |
set the clipboard to oldClip | |
end if | |
if ans is not equal to 0 then | |
if defTab = 0 then | |
set the clipboard to myT | |
delay 0.02 | |
tell application "System Events" | |
keystroke "v" using command down | |
end tell | |
delay 0.5 | |
set the clipboard to oldClip | |
end if -- noTab = 0 then | |
end if | |
-- end of script 2-Remove Empty Lines and Tabs at the End of Line | |
--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment