Skip to content

Instantly share code, notes, and snippets.

@OKsign
Created May 9, 2018 09:19
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 OKsign/5ba24094f504d1662c023e599aab49b4 to your computer and use it in GitHub Desktop.
Save OKsign/5ba24094f504d1662c023e599aab49b4 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<root>
<vkopenurldef>
<name>KeyCode::VK_OPEN_URL_83</name>
<url type="shell">
osascript -e '
set sName to "83"
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 83: Capitalize Words with Exceptions_Hold A</name>
<identifier>My Key 83: Capitalize Words with Exceptions_Hold A</identifier>
<autogen>
--HoldingKeyToKey--
KeyCode::A, ModifierFlag::NONE,
@begin
KeyCode::A,
@end
@begin
<!-- run via script menu -->
KeyCode::VK_OPEN_URL_83,
@end
Option::NOREPEAT,
</autogen>
</item>
</root>
<!-- script for my key 83.2
-- user input
set LowerCase to {"foobar", "to", "with", "in", "from", "and", "of","by","at"}
set UpperCase to {"atom", "vlc"}
set UpperLower to {"UMPlayer", "VideoSpec"}
-- end of user input
set aList to LowerCase & UpperCase & UpperLower
set igList to {"|"}
tell application "System Events"
keystroke "c" using command down
delay 0.7
set CopT to (the clipboard as text)
end tell
set posList to {}
repeat with x from 1 to (count every character of CopT)
if character x of CopT is "'" then
copy x to the end of posList
end if
end repeat
if CopT contains "'" then
set AppleScript's text item delimiters to {"'"}
set the item_list to every text item of CopT
set AppleScript's text item delimiters to the ""
set CopT to the item_list as string
end if
set AppleScript's text item delimiters to {" "}
set myText1 to ""
repeat with N from 1 to (count text item of CopT)
if (text item N of CopT) is not in aList then
delay 0.05
if length of (text item N of CopT) is greater than 2 then
delay 0.2
-- add
if (text item N of CopT) contains "'" then
end if
-- end add
set aText to do shell script "echo " & character 1 of (text item N of CopT) & " | tr [:lower:] [:upper:]"
repeat with x from 2 to count (text item N of CopT)
set bText to do shell script "echo " & character x of (text item N of CopT) & " | tr [:upper:] [:lower:]"
set aText to aText & bText
end repeat
end if
if length of (text item N of CopT) is 1 then
if (text item N of CopT) is in igList then
set aText to "|"
else
set aText to do shell script "echo " & character 1 of (text item N of CopT) & " | tr [:lower:] [:upper:]"
end if
end if
if length of (text item N of CopT) is equal to 2 then
delay 0.2
set aText to do shell script "echo " & character 1 of (text item N of CopT) & " | tr [:lower:] [:upper:]"
repeat with x from 2 to count (text item N of CopT)
set bText to do shell script "echo " & character x of (text item N of CopT) & " | tr [:upper:] [:lower:]"
set aText to aText & bText
end repeat
end if
end if
if LowerCase contains (text item N of CopT) then
delay 0.02
set aText to do shell script "echo " & text item N of CopT & " | tr [:upper:] [:lower:] "
end if
delay 0.02
if UpperCase contains (text item N of CopT) then
delay 0.02
set aText to do shell script "echo " & text item N of CopT & " | tr [:lower:] [:upper:] "
end if
if UpperLower contains (text item N of CopT) then
delay 0.02
set Fitem to text item N of CopT
repeat with i from 1 to (count UpperLower)
if Fitem is item i of UpperLower then
delay 0.02
set aText to item i of UpperLower
exit repeat
end if
end repeat
end if
set myText1 to myText1 & aText & " "
end repeat
delay 0.02
set Lencopt to (length of CopT) + (count posList)
-- add
set acount to count every character of myText1
set myText2 to ""
if (count posList) = 1 then
repeat with i from 1 to acount
if i is in posList then
set c to "'" & character i of myText1
else
set c to character i of myText1
end if
set myText2 to myText2 & c
end repeat
set myText1 to myText2
else
if (count posList) > 1 then
set posList2 to {}
set y to 0
set x to 0
repeat with i from 1 to count posList
set x to x + y
copy ((item i of posList) - x) to the end of posList2
set y to 1
end repeat
repeat with i from 1 to acount
if i is in posList2 then
set c to "'" & character i of myText1
else
set c to character i of myText1
end if
set myText2 to myText2 & c
end repeat
set myText1 to myText2
end if -- (count posList) > 1
end if
-- end add
set the clipboard to myText1
delay 0.03
tell application "System Events"
keystroke "v" using command down
delay 0.02
key code 51
delay 0.02
repeat Lencopt times
key code 123 using shift down
delay 0.01
end repeat
end tell
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment