Skip to content

Instantly share code, notes, and snippets.

Created March 20, 2018 07:37
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 anonymous/38d240c0919e2e19e7a4674b7005d913 to your computer and use it in GitHub Desktop.
Save anonymous/38d240c0919e2e19e7a4674b7005d913 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<root>
<vkopenurldef>
<name>KeyCode::VK_OPEN_URL_88.1</name>
<url type="shell">
osascript -e '
set sName to "88.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>
<item>
<name>My Key 88.1: Rename Active Document_Hold N</name>
<identifier>My Key 88.1: Rename Active Document_Hold N</identifier>
<not>FINDER,ITUNES,FIREFOX,SAFARI,GOOGLE_CHROME,MAIL,VLC,QUICKTIME,SYSTEM_PREFERENCES,OPERA</not>
<autogen>
--HoldingKeyToKey--
KeyCode::N, ModifierFlag::NONE,
@begin
KeyCode::N,
@end
@begin
<!-- run via script menu -->
KeyCode::VK_OPEN_URL_88.1,
@end
Option::NOREPEAT,
</autogen>
</item>
</root>
<!-- script for my key 88.1 (Save this script as 88.1)
-- user options
set CloseWindow to "yes" -- "yes" or "no" (use command + w)
-- end of user options
tell application "System Events"
set activeApp to (get name of first process where it is frontmost)
end tell
tell application "System Events"
tell process activeApp
set docPath1 to value of attribute "AXDocument" of window 1
end tell
end tell
if docPath1 is not missing value then
if docPath1 contains "%20" then
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to the "%20" -- search
set the item_list to every text item of docPath1 -- original text
delay 0.04
set AppleScript's text item delimiters to the " " -- replace
set docPath1 to the item_list as string
set AppleScript's text item delimiters to prevTIDs
end if
delay 0.02
if docPath1 contains "%" then
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to the "%25" -- search
set the item_list to every text item of docPath1 -- original text
delay 0.04
set AppleScript's text item delimiters to the "%" -- replace
set docPath1 to the item_list as string
set AppleScript's text item delimiters to prevTIDs
end if
delay 0.02
if docPath1 contains "localhost" then -- remove characters
set docPath1 to ((characters 17 thru -1 of docPath1) as string)
else
set docPath1 to ((characters 8 thru -1 of docPath1) as string)
end if
end if
set tar to POSIX file docPath1
tell application "Finder"
select tar
set tar to selection
delay 0.5
repeat with x in tar
set fName to (get name of x)
set AppleScript's text item delimiters to "."
if (count text item of fName) is equal to 2 then
set OldName to text item 1 of fName
end if
if (count text item of fName) is greater than 2 then
set OldName to ""
repeat with i from 1 to ((count text item of fName) - 2)
delay 0.02
set OldName to OldName & (text item i of fName) & "."
end repeat
delay 0.02
set OldName to OldName & text item ((count text item of fName) - 1) of fName
end if
end repeat
end tell
try
set uName to the text returned of (display dialog "Name:" default answer OldName with title "my key 88.1")
on error number -128
if CloseWindow is "yes" then
tell application "System Events"
tell process "Finder"
set frontmost to true
end tell
end tell
delay 0.4
tell application "System Events"
keystroke "w" using command down
end tell
delay 1
tell application "System Events"
tell process activeApp
set frontmost to true
end tell
end tell
return
end if
end try
if uName is not "" then
if activeApp is "soffice" then -- activeApp is OpenOffice, close document window
tell application "System Events"
tell process activeApp
set frontmost to true
end tell
end tell
delay 0.3
tell application "System Events"
keystroke "s" using command down
delay 3
keystroke "w" using command down
end tell
end if -- activeApp is "soffice"
tell application "System Events"
tell process "Finder"
set frontmost to true
end tell
end tell
delay 0.4
tell application "System Events"
key code 36
delay 0.5
keystroke uName
delay 0.3
key code 36
end tell
delay 0.8
if activeApp is "soffice" then
tell application "System Events"
keystroke "o" using command down
delay 0.5
set activeApp2 to (get name of first process where it is frontmost)
end tell
if CloseWindow is "yes" then
repeat until activeApp2 is "Finder"
tell application "System Events"
tell process "Finder"
set frontmost to true
end tell
end tell
delay 0.03
tell application "System Events"
set activeApp2 to (get name of first process where it is frontmost)
end tell
end repeat
delay 0.02
tell application "System Events"
keystroke "w" using command down
end tell
end if
end if
if activeApp is not "soffice" then
if CloseWindow is "yes" then
tell application "System Events"
tell process "Finder"
set frontmost to true
end tell
end tell
delay 0.4
tell application "System Events"
keystroke "w" using command down
end tell
end if
end if
tell application "System Events"
tell process activeApp
set frontmost to true
end tell
end tell
delay 0.5
display notification "Done!" with title "my key 88.1"
else
if CloseWindow is "yes" then
tell application "System Events"
tell process "Finder"
set frontmost to true
end tell
end tell
delay 0.4
tell application "System Events"
keystroke "w" using command down
end tell
end if
tell application "System Events"
tell process activeApp
set frontmost to true
end tell
end tell
delay 0.5
display notification "Done!" with title "my key 88.1"
end if -- uName is not ""
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment