-
Notifications
You must be signed in to change notification settings - Fork 211
Contributed Scripts 4
Elliria edited this page Oct 10, 2025
·
4 revisions
- Create a phrase from a script
- Create one or more phrases from a CSV file
- Create one or more phrases from a text file
- Author: Elliria
-
Purpose This script creates a phrase. If its name already exists, a new phrase is created by the same name with a number appended to it. This script was successfully tested in AutoKey 0.95.10.
# Store the phrase folder in a variable (the default name is My Phrases): folder = engine.get_folder("My Phrases") # Store the phrase name in a variable: phrase_name = "New phrase" # Store the phrase contents in a variable: phrase_contents = "hello world" # Create the new phrase: engine.create_phrase(folder, phrase_name, phrase_contents) # Display a closing dialog: dialog.info_dialog("Info", "Done. Close and reopen AutoKey to see the phrase.")
- Author: Elliria
- Purpose This script reads the contents of the specified CSV file row by row and creates a new phrase from each row while ignoring empty rows. This script was successfully tested in AutoKey 0.95.10.
-
Note Customize the script by replacing the example file_path and folder locations with those you'd like to use.
# Import the CSV module: import csv # Try to open the CSV file and create one or more phrases from it: try: # Store a starting value for the row_count variable: row_count = 0 # Store the path to the CSV file in a variable: file_path = "/home/elliria/Desktop/example.csv" # Store the folder that the phrases are in in a variable: folder = engine.get_folder("My Phrases") # Open the CSV file: with open(file_path,'r') as csvfile: for row in csv.reader(csvfile): # If the row isn't empty after stripping: if str(row).strip(): # Add 1 to the line_count value: row_count += 1 # Store a phrase name that uses the current row_count: phrase_name = f"Phrase{row_count}" # Create the new phrase: engine.create_phrase(folder, phrase_name, str(row)) # Display a closing dialog: dialog.info_dialog("Info", "Done. Close and reopen AutoKey to see them.") # If the file doesn't exist: except FileNotFoundError: # Display an error dialog: dialog.info_dialog("Error", f"File not found: {file_path}") # Exit without continuing the script: exit()
- Author: Elliria
- Purpose This script reads the contents of the specified text file line by line and creates a new phrase from each line while ignoring empty lines. This script was successfully tested in AutoKey 0.95.10.
-
Note Customize the script by replacing the example file_path and folder locations with those you'd like to use.
# Try to open the text file and create one or more phrases from it: try: # Store a starting value for the line_count variable: line_count = 0 # Store the path to the text file in a variable: file_path = "/home/elliria/Desktop/example.txt" # Store the folder that the phrases are in in a variable: folder = engine.get_folder("My Phrases") # Open the file: with open(file_path, "r") as f: for line in f: # If the line isn't empty after stripping: if line.strip(): # Add 1 to the line_count value: line_count += 1 # Store a phrase name that uses the current line_count: phrase_name = f"Phrase{line_count}" # Create the new phrase: engine.create_phrase(folder, phrase_name, line) # Display a closing dialog: dialog.info_dialog("Info", "Done. Close and reopen AutoKey to see them.") # If the file doesn't exist: except FileNotFoundError: # Display an error dialog: dialog.info_dialog("Error", f"File not found: {file_path}") # Exit without continuing the script: exit()
-
Home
- About
- Beginners' Guide
- Documentation
- FAQ
- Administration
- Community
- Development
- Features