autokey2espanso 1.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Johann Judek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,140 @@
1
+ Metadata-Version: 2.4
2
+ Name: autokey2espanso
3
+ Version: 1.0.2
4
+ Summary: Convert AutoKey phrase entries to Espanso YAML format
5
+ Author: Johann Judek
6
+ License: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # autokey2espanso
13
+
14
+ Convert AutoKey phrase entries into Espanso YAML configuration.
15
+
16
+ ## Why?
17
+
18
+ If you are migrating from AutoKey to Espanso, this tool converts your existing phrase entries automatically.
19
+
20
+ It reads matching `.json` and `.txt` pairs and generates a valid Espanso `matches:` configuration.
21
+
22
+ ---
23
+
24
+ ## Requirements
25
+
26
+ * Python 3.8+
27
+
28
+ ---
29
+
30
+ ## Installation
31
+
32
+ Clone the repository:
33
+
34
+ ```bash
35
+ git clone https://github.com/johannjdk/autokey2espanso.git
36
+ cd autokey2espanso
37
+ pip install .
38
+ ```
39
+
40
+ Or run directly:
41
+
42
+ ```bash
43
+ python3 autokey2espanso/cli.py <directory>
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Usage
49
+
50
+ Basic usage (prints YAML to stdout):
51
+
52
+ ```bash
53
+ autokey2espanso /path/to/autokey/phrases
54
+ ```
55
+
56
+ Write output to file:
57
+
58
+ ```bash
59
+ autokey2espanso /path/to/autokey/phrases -o espanso.yml
60
+ ```
61
+
62
+ Verbose mode:
63
+
64
+ ```bash
65
+ autokey2espanso /path/to/autokey/phrases -o espanso.yml -v
66
+ ```
67
+
68
+ Word mode (`-w / --wordmode`):
69
+
70
+ ```bash
71
+ autokey2espanso /path/to/autokey/phrases -o espanso.yml -w
72
+ ```
73
+
74
+ Custom prefix (`-p / --prefix`):
75
+
76
+ ```bash
77
+ autokey2espanso /path/to/autokey/phrases -p ":" -o espanso.yml
78
+ ```
79
+
80
+ When enabled, the prefix will be added before each trigger.
81
+ If omitted, triggers are taken **1:1** from AutoKey.
82
+
83
+ When word mode is enabled, each entry will include:
84
+
85
+ ```yaml
86
+ word: true
87
+ ```
88
+
89
+ This is useful for triggers that should only match entire words in Espanso.
90
+
91
+ ---
92
+
93
+ ## How it works
94
+
95
+ For each entry, both files must exist:
96
+
97
+ ```
98
+ Example.json
99
+ Example.txt
100
+ ```
101
+
102
+ The first abbreviation inside the JSON file becomes the Espanso trigger. With optional prefix:
103
+
104
+ ```json
105
+ "abbreviations": ["hello"]
106
+ ```
107
+
108
+ Becomes with `-p ":"`:
109
+
110
+ ```yaml
111
+ matches:
112
+ - trigger: ":hello"
113
+ replace: |
114
+ Hello World!
115
+ ```
116
+
117
+ Or 1:1 (no prefix):
118
+
119
+ ```yaml
120
+ matches:
121
+ - trigger: "hello"
122
+ replace: |
123
+ Hello World!
124
+ ```
125
+
126
+ If word mode is enabled:
127
+
128
+ ```yaml
129
+ matches:
130
+ - trigger: ":hello"
131
+ word: true
132
+ replace: |
133
+ Hello World!
134
+ ```
135
+
136
+ ---
137
+
138
+ ## License
139
+
140
+ MIT
@@ -0,0 +1,129 @@
1
+ # autokey2espanso
2
+
3
+ Convert AutoKey phrase entries into Espanso YAML configuration.
4
+
5
+ ## Why?
6
+
7
+ If you are migrating from AutoKey to Espanso, this tool converts your existing phrase entries automatically.
8
+
9
+ It reads matching `.json` and `.txt` pairs and generates a valid Espanso `matches:` configuration.
10
+
11
+ ---
12
+
13
+ ## Requirements
14
+
15
+ * Python 3.8+
16
+
17
+ ---
18
+
19
+ ## Installation
20
+
21
+ Clone the repository:
22
+
23
+ ```bash
24
+ git clone https://github.com/johannjdk/autokey2espanso.git
25
+ cd autokey2espanso
26
+ pip install .
27
+ ```
28
+
29
+ Or run directly:
30
+
31
+ ```bash
32
+ python3 autokey2espanso/cli.py <directory>
33
+ ```
34
+
35
+ ---
36
+
37
+ ## Usage
38
+
39
+ Basic usage (prints YAML to stdout):
40
+
41
+ ```bash
42
+ autokey2espanso /path/to/autokey/phrases
43
+ ```
44
+
45
+ Write output to file:
46
+
47
+ ```bash
48
+ autokey2espanso /path/to/autokey/phrases -o espanso.yml
49
+ ```
50
+
51
+ Verbose mode:
52
+
53
+ ```bash
54
+ autokey2espanso /path/to/autokey/phrases -o espanso.yml -v
55
+ ```
56
+
57
+ Word mode (`-w / --wordmode`):
58
+
59
+ ```bash
60
+ autokey2espanso /path/to/autokey/phrases -o espanso.yml -w
61
+ ```
62
+
63
+ Custom prefix (`-p / --prefix`):
64
+
65
+ ```bash
66
+ autokey2espanso /path/to/autokey/phrases -p ":" -o espanso.yml
67
+ ```
68
+
69
+ When enabled, the prefix will be added before each trigger.
70
+ If omitted, triggers are taken **1:1** from AutoKey.
71
+
72
+ When word mode is enabled, each entry will include:
73
+
74
+ ```yaml
75
+ word: true
76
+ ```
77
+
78
+ This is useful for triggers that should only match entire words in Espanso.
79
+
80
+ ---
81
+
82
+ ## How it works
83
+
84
+ For each entry, both files must exist:
85
+
86
+ ```
87
+ Example.json
88
+ Example.txt
89
+ ```
90
+
91
+ The first abbreviation inside the JSON file becomes the Espanso trigger. With optional prefix:
92
+
93
+ ```json
94
+ "abbreviations": ["hello"]
95
+ ```
96
+
97
+ Becomes with `-p ":"`:
98
+
99
+ ```yaml
100
+ matches:
101
+ - trigger: ":hello"
102
+ replace: |
103
+ Hello World!
104
+ ```
105
+
106
+ Or 1:1 (no prefix):
107
+
108
+ ```yaml
109
+ matches:
110
+ - trigger: "hello"
111
+ replace: |
112
+ Hello World!
113
+ ```
114
+
115
+ If word mode is enabled:
116
+
117
+ ```yaml
118
+ matches:
119
+ - trigger: ":hello"
120
+ word: true
121
+ replace: |
122
+ Hello World!
123
+ ```
124
+
125
+ ---
126
+
127
+ ## License
128
+
129
+ MIT
@@ -0,0 +1 @@
1
+ __version__ = "1.0.2"
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import argparse
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+ from datetime import datetime
8
+
9
+
10
+ def verbose_print(enabled, message):
11
+ if enabled:
12
+ timestamp = datetime.now().strftime("%H:%M:%S")
13
+ print(f"[{timestamp}] {message}", file=sys.stderr)
14
+
15
+
16
+ def collect_entries(directory: Path, verbose: bool, prefix: str):
17
+ entries = []
18
+ json_files = sorted(directory.glob("*.json"))
19
+
20
+ verbose_print(verbose, f"Scanning directory: {directory}")
21
+ verbose_print(verbose, f"Found {len(json_files)} JSON files")
22
+
23
+ for json_file in json_files:
24
+ base_name = json_file.stem
25
+ txt_file = directory / f"{base_name}.txt"
26
+
27
+ if not txt_file.exists():
28
+ verbose_print(verbose, f"Skipping '{base_name}': missing .txt file")
29
+ continue
30
+
31
+ try:
32
+ with json_file.open("r", encoding="utf-8") as jf:
33
+ data = json.load(jf)
34
+ except Exception as e:
35
+ verbose_print(verbose, f"Skipping '{base_name}': JSON error ({e})")
36
+ continue
37
+
38
+ abbreviations = (
39
+ data.get("abbreviation", {})
40
+ .get("abbreviations", [])
41
+ )
42
+
43
+ if not abbreviations:
44
+ verbose_print(verbose, f"Skipping '{base_name}': no abbreviation found")
45
+ continue
46
+
47
+ trigger = abbreviations[0]
48
+ if prefix:
49
+ trigger = f"{prefix}{trigger}"
50
+
51
+ try:
52
+ with txt_file.open("r", encoding="utf-8") as tf:
53
+ content = tf.read().rstrip()
54
+ except Exception as e:
55
+ verbose_print(verbose, f"Skipping '{base_name}': TXT read error ({e})")
56
+ continue
57
+
58
+ entries.append((trigger, content))
59
+ verbose_print(verbose, f"Processed '{base_name}' -> trigger '{trigger}'")
60
+
61
+ verbose_print(verbose, f"Successfully processed {len(entries)} entries")
62
+ return entries
63
+
64
+
65
+ def generate_yaml(entries, wordmode=False):
66
+ lines = ["matches:"]
67
+ for trigger, content in entries:
68
+ lines.append(f" - trigger: \"{trigger}\"")
69
+ if wordmode:
70
+ lines.append(" word: true")
71
+ lines.append(" replace: |-")
72
+ for line in content.splitlines():
73
+ lines.append(f" {line}")
74
+ return "\n".join(lines) + "\n"
75
+
76
+
77
+ def main():
78
+ parser = argparse.ArgumentParser(
79
+ description="Convert AutoKey phrase entries to Espanso YAML format."
80
+ )
81
+ parser.add_argument("directory", help="Directory containing AutoKey entries")
82
+ parser.add_argument("-o", "--output", help="Output file path")
83
+ parser.add_argument("-v", "--verbose", action="store_true", help="Verbose mode")
84
+ parser.add_argument(
85
+ "-w", "--wordmode", action="store_true", help="Add 'word: true' to each entry"
86
+ )
87
+ parser.add_argument(
88
+ "-p", "--prefix", help="Custom prefix to add to triggers", default=""
89
+ )
90
+ args = parser.parse_args()
91
+
92
+ directory = Path(args.directory)
93
+
94
+ if not directory.is_dir():
95
+ print("Error: Invalid directory", file=sys.stderr)
96
+ sys.exit(1)
97
+
98
+ entries = collect_entries(directory, args.verbose, args.prefix)
99
+ yaml_output = generate_yaml(entries, wordmode=args.wordmode)
100
+
101
+ if args.output:
102
+ output_path = Path(args.output)
103
+ try:
104
+ with output_path.open("w", encoding="utf-8") as f:
105
+ f.write(yaml_output)
106
+ verbose_print(args.verbose, f"YAML written to {output_path}")
107
+ sys.exit(0)
108
+ except Exception as e:
109
+ print(f"Error writing output file: {e}", file=sys.stderr)
110
+ sys.exit(1)
111
+ else:
112
+ print(yaml_output, end="")
113
+ sys.exit(0)
114
+
115
+
116
+ if __name__ == "__main__":
117
+ main()
@@ -0,0 +1,140 @@
1
+ Metadata-Version: 2.4
2
+ Name: autokey2espanso
3
+ Version: 1.0.2
4
+ Summary: Convert AutoKey phrase entries to Espanso YAML format
5
+ Author: Johann Judek
6
+ License: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # autokey2espanso
13
+
14
+ Convert AutoKey phrase entries into Espanso YAML configuration.
15
+
16
+ ## Why?
17
+
18
+ If you are migrating from AutoKey to Espanso, this tool converts your existing phrase entries automatically.
19
+
20
+ It reads matching `.json` and `.txt` pairs and generates a valid Espanso `matches:` configuration.
21
+
22
+ ---
23
+
24
+ ## Requirements
25
+
26
+ * Python 3.8+
27
+
28
+ ---
29
+
30
+ ## Installation
31
+
32
+ Clone the repository:
33
+
34
+ ```bash
35
+ git clone https://github.com/johannjdk/autokey2espanso.git
36
+ cd autokey2espanso
37
+ pip install .
38
+ ```
39
+
40
+ Or run directly:
41
+
42
+ ```bash
43
+ python3 autokey2espanso/cli.py <directory>
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Usage
49
+
50
+ Basic usage (prints YAML to stdout):
51
+
52
+ ```bash
53
+ autokey2espanso /path/to/autokey/phrases
54
+ ```
55
+
56
+ Write output to file:
57
+
58
+ ```bash
59
+ autokey2espanso /path/to/autokey/phrases -o espanso.yml
60
+ ```
61
+
62
+ Verbose mode:
63
+
64
+ ```bash
65
+ autokey2espanso /path/to/autokey/phrases -o espanso.yml -v
66
+ ```
67
+
68
+ Word mode (`-w / --wordmode`):
69
+
70
+ ```bash
71
+ autokey2espanso /path/to/autokey/phrases -o espanso.yml -w
72
+ ```
73
+
74
+ Custom prefix (`-p / --prefix`):
75
+
76
+ ```bash
77
+ autokey2espanso /path/to/autokey/phrases -p ":" -o espanso.yml
78
+ ```
79
+
80
+ When enabled, the prefix will be added before each trigger.
81
+ If omitted, triggers are taken **1:1** from AutoKey.
82
+
83
+ When word mode is enabled, each entry will include:
84
+
85
+ ```yaml
86
+ word: true
87
+ ```
88
+
89
+ This is useful for triggers that should only match entire words in Espanso.
90
+
91
+ ---
92
+
93
+ ## How it works
94
+
95
+ For each entry, both files must exist:
96
+
97
+ ```
98
+ Example.json
99
+ Example.txt
100
+ ```
101
+
102
+ The first abbreviation inside the JSON file becomes the Espanso trigger. With optional prefix:
103
+
104
+ ```json
105
+ "abbreviations": ["hello"]
106
+ ```
107
+
108
+ Becomes with `-p ":"`:
109
+
110
+ ```yaml
111
+ matches:
112
+ - trigger: ":hello"
113
+ replace: |
114
+ Hello World!
115
+ ```
116
+
117
+ Or 1:1 (no prefix):
118
+
119
+ ```yaml
120
+ matches:
121
+ - trigger: "hello"
122
+ replace: |
123
+ Hello World!
124
+ ```
125
+
126
+ If word mode is enabled:
127
+
128
+ ```yaml
129
+ matches:
130
+ - trigger: ":hello"
131
+ word: true
132
+ replace: |
133
+ Hello World!
134
+ ```
135
+
136
+ ---
137
+
138
+ ## License
139
+
140
+ MIT
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ autokey2espanso/__init__.py
5
+ autokey2espanso/cli.py
6
+ autokey2espanso.egg-info/PKG-INFO
7
+ autokey2espanso.egg-info/SOURCES.txt
8
+ autokey2espanso.egg-info/dependency_links.txt
9
+ autokey2espanso.egg-info/entry_points.txt
10
+ autokey2espanso.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ autokey2espanso = autokey2espanso.cli:main
@@ -0,0 +1 @@
1
+ autokey2espanso
@@ -0,0 +1,13 @@
1
+ [project]
2
+ name = "autokey2espanso"
3
+ version = "1.0.2"
4
+ description = "Convert AutoKey phrase entries to Espanso YAML format"
5
+ authors = [
6
+ {name = "Johann Judek"}
7
+ ]
8
+ readme = "README.md"
9
+ requires-python = ">=3.8"
10
+ license = {text = "MIT"}
11
+
12
+ [project.scripts]
13
+ autokey2espanso = "autokey2espanso.cli:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+