### Keyboard Shortcut Assignment Examples Source: https://github.com/coteditor/coteditor/blob/main/CotEditor/Resources/CotEditor.help/Contents/Resources/en.lproj/pgs/script_menu.html Examples demonstrating how to assign keyboard shortcuts to scripts by modifying filenames. ```text Filename Show in the menu Shortcut Insert Text**.@e**.scpt Insert Text Command\-E 03)Insert Date**.@~Y**.scpt Insert Date Option\-Shift\-Command\-Y ``` -------------------------------- ### Filename to Menu Item Example Source: https://github.com/coteditor/coteditor/blob/main/CotEditor/Resources/CotEditor.help/Contents/Resources/en.lproj/pgs/script_menu.html Example showing how a prefixed filename translates to its appearance in the Script menu. ```text Filename Show in the menu **01)**Open File.scpt Open File ``` -------------------------------- ### Example for folder document Source: https://github.com/coteditor/coteditor/blob/main/CotEditor/Resources/CotEditor.help/Contents/Resources/en.lproj/pgs/script_osascript.html The following two commands produce the same result: Gets the front text document and sets its selection contents. ```AppleScript if front document is folder document then set theDocument to front document's current document else set theDocument to front document end if tell theDocument set theText to contents of selection end tell ``` -------------------------------- ### Info.plist Example Source: https://github.com/coteditor/coteditor/blob/main/CotEditor/Resources/CotEditor.help/Contents/Resources/en.lproj/pgs/script_hook.html An example of the Info.plist file within a script bundle, showing how to declare the events to subscribe to using the CotEditorHandlers key. ```xml CFBundleIdentifier com.coteditor.hooking-script CFBundleName Hooking Script CFBundleShortVersionString 1.0 ``` -------------------------------- ### Separator Example Source: https://github.com/coteditor/coteditor/blob/main/CotEditor/Resources/CotEditor.help/Contents/Resources/en.lproj/pgs/script_menu.html Example of how to create a separator in the Script menu using a specific filename format. ```text A file or folder named “-” becomes a separator in the Script menu. You can place it at a specific position by adding a number followed by a closing parenthesis at the beginning of the name (for example, “02)-”). ``` -------------------------------- ### Python Script Example Source: https://github.com/coteditor/coteditor/blob/main/CotEditor/Resources/CotEditor.help/Contents/Resources/en.lproj/pgs/script_unixscript.html An example Python script that adds a '>' character to the beginning of each selected line and prints the number of processed lines to the Console. ```python #!/usr/bin/env python3 # %%%{CotEditorXInput=Selection}%%% # %%%{CotEditorXOutput=ReplaceSelection}%%% import sys count = 0 for line in sys.stdin: count += 1 print(">" + line.rstrip()) sys.stderr.write("Processed {} lines.".format(count)) ``` -------------------------------- ### Hiding Files Example Source: https://github.com/coteditor/coteditor/blob/main/CotEditor/Resources/CotEditor.help/Contents/Resources/en.lproj/pgs/script_menu.html Explanation of how filenames starting with an underscore are hidden from the Script menu. ```text A file or folder whose name begins with an underscore “_” doesn’t appear in the Script menu. You can use these items for settings files, library scripts, and other supporting resources. ``` -------------------------------- ### Find Command Example Source: https://github.com/coteditor/coteditor/blob/main/CotEditor/Resources/CotEditor.help/Contents/Resources/en.lproj/pgs/script_osascript.html Searches for 'Apple' in the front document, ignoring case, starting from the current selection to the end of the document. ```osascript find front document for "Apple" with ignore case ``` -------------------------------- ### Specifying the target for the selection object Source: https://github.com/coteditor/coteditor/blob/main/CotEditor/Resources/CotEditor.help/Contents/Resources/en.lproj/pgs/script_osascript_changes.html Examples demonstrating how to correctly specify the target when getting the selection object in CotEditor 1.5 and later. ```applescript tell application "CotEditor" contents of selection of front document end tell ``` ```applescript tell application "CotEditor" tell document 1 contents of selection end tell end tell ``` -------------------------------- ### Example for folder document Source: https://github.com/coteditor/coteditor/blob/main/CotEditor/Resources/CotEditor.help/Contents/Resources/en.lproj/pgs/script_osascript.html Sets the selection contents of the front document. ```AppleScript tell front document set theText to contents of selection end tell ``` -------------------------------- ### JavaScript Example Source: https://github.com/coteditor/coteditor/blob/main/Packages/Syntax/Tests/SyntaxParsersTests/Samples/test.html A simple JavaScript snippet to demonstrate variable usage. ```javascript const user = { id: 1, name: "Alice" }; console.log(`user:${user.id}:${user.name}`); ``` -------------------------------- ### Write to Console Example Source: https://github.com/coteditor/coteditor/blob/main/CotEditor/Resources/CotEditor.help/Contents/Resources/en.lproj/pgs/script_osascript.html Displays a message on CotEditor's console. The first example shows the default behavior with script name and timestamp, while the second demonstrates how to suppress them. ```osascript write to console "Script failed." ``` ```osascript write to console "calculating…" without title and timestamp ``` -------------------------------- ### File Extension Mapping Example Source: https://github.com/coteditor/coteditor/blob/main/CotEditor/Resources/CotEditor.help/Contents/Resources/en.lproj/pgs/syntax_file_mapping.html If filename matching fails, CotEditor uses file extensions. Case is generally ignored, but exact matches are preferred. ```text .html → HTML .hTmL → HTML .py → Python ```