mac-helper 0.6.0 → 0.8.0
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.
- package/lib/dialog.js +1 -0
- package/lib/finder.d.ts +8 -1
- package/lib/finder.js +33 -8
- package/package.json +23 -32
- package/src/chrome.ts +1 -1
- package/src/dialog.ts +2 -1
- package/src/finder.ts +33 -8
package/lib/dialog.js
CHANGED
package/lib/finder.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const PathFinder: {
|
|
|
5
5
|
allSelected(): Promise<string[]>;
|
|
6
6
|
singleSelected(): Promise<string | undefined>;
|
|
7
7
|
setSelected(filePaths: string[]): Promise<void>;
|
|
8
|
+
getActiveTabDir: typeof PathFinder_getActiveTabDir;
|
|
8
9
|
};
|
|
9
10
|
export declare const Finder: {
|
|
10
11
|
allSelected(): Promise<string[]>;
|
|
@@ -15,6 +16,11 @@ export declare const QSpace: {
|
|
|
15
16
|
allSelected(): Promise<string[]>;
|
|
16
17
|
singleSelected(): Promise<string | undefined>;
|
|
17
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* 获取 activeTab dir, 当没有 selection 时可用,
|
|
21
|
+
* 要求只能有一个 visible window, 从 jxa 这一层无法区分 window z-index
|
|
22
|
+
*/
|
|
23
|
+
declare function PathFinder_getActiveTabDir(): Promise<string | undefined>;
|
|
18
24
|
export type QSpaceFileItem = {
|
|
19
25
|
id: () => string;
|
|
20
26
|
name: () => string;
|
|
@@ -23,6 +29,7 @@ export type QSpaceFileItem = {
|
|
|
23
29
|
export declare function isRepresentPF(file: string): boolean;
|
|
24
30
|
export declare function isRepresentQS(file: string): boolean;
|
|
25
31
|
/**
|
|
26
|
-
* 处理
|
|
32
|
+
* 处理 `@pf` `@qs`, ignore case
|
|
27
33
|
*/
|
|
28
34
|
export declare function normalizeInputFileList(fileList: string[]): Promise<string[]>;
|
|
35
|
+
export {};
|
package/lib/finder.js
CHANGED
|
@@ -27,6 +27,7 @@ exports.PathFinder = {
|
|
|
27
27
|
setSelected(filePaths) {
|
|
28
28
|
return PathFinder_setSelected(filePaths);
|
|
29
29
|
},
|
|
30
|
+
getActiveTabDir: PathFinder_getActiveTabDir,
|
|
30
31
|
};
|
|
31
32
|
exports.Finder = {
|
|
32
33
|
allSelected() {
|
|
@@ -67,8 +68,7 @@ async function PathFinder_singleSelected() {
|
|
|
67
68
|
}
|
|
68
69
|
const firstFilePath = await (0, run_1.run)(() => {
|
|
69
70
|
const app = Application('Path Finder');
|
|
70
|
-
|
|
71
|
-
return arr[0];
|
|
71
|
+
return (app.selection() || [])[0]?.posixPath();
|
|
72
72
|
});
|
|
73
73
|
return firstFilePath;
|
|
74
74
|
}
|
|
@@ -78,6 +78,29 @@ async function PathFinder_setSelected(filePaths) {
|
|
|
78
78
|
app.select(filePaths);
|
|
79
79
|
}, filePaths);
|
|
80
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* 获取 activeTab dir, 当没有 selection 时可用,
|
|
83
|
+
* 要求只能有一个 visible window, 从 jxa 这一层无法区分 window z-index
|
|
84
|
+
*/
|
|
85
|
+
async function PathFinder_getActiveTabDir() {
|
|
86
|
+
if (!(await (0, app_1.isAppRunning)('Path Finder')))
|
|
87
|
+
return;
|
|
88
|
+
const visibleWindowCount = await (0, run_1.run)(() => {
|
|
89
|
+
const app = Application('Path Finder');
|
|
90
|
+
return app.finderWindows.whose({ visible: true }).length;
|
|
91
|
+
});
|
|
92
|
+
if (!visibleWindowCount)
|
|
93
|
+
return;
|
|
94
|
+
if (visibleWindowCount > 1) {
|
|
95
|
+
throw new Error('Multiple visible PathFinder window not supported in PathFinder_getActiveTabDir');
|
|
96
|
+
}
|
|
97
|
+
const dir = await (0, run_1.run)(() => {
|
|
98
|
+
const app = Application('Path Finder');
|
|
99
|
+
const w = app.finderWindows.whose({ visible: true })[0];
|
|
100
|
+
return w.target.posixPath();
|
|
101
|
+
});
|
|
102
|
+
return dir;
|
|
103
|
+
}
|
|
81
104
|
/* #endregion */
|
|
82
105
|
/* #region Finder */
|
|
83
106
|
async function Finder_allSelected() {
|
|
@@ -109,13 +132,13 @@ async function QSpace_allSelected() {
|
|
|
109
132
|
/* #endregion */
|
|
110
133
|
/* #region Top Level Helper */
|
|
111
134
|
function isRepresentPF(file) {
|
|
112
|
-
return
|
|
135
|
+
return /^[@$]?pf$/i.test(file);
|
|
113
136
|
}
|
|
114
137
|
function isRepresentQS(file) {
|
|
115
|
-
return
|
|
138
|
+
return /^[@$]?qs$/i.test(file);
|
|
116
139
|
}
|
|
117
140
|
/**
|
|
118
|
-
* 处理
|
|
141
|
+
* 处理 `@pf` `@qs`, ignore case
|
|
119
142
|
*/
|
|
120
143
|
async function normalizeInputFileList(fileList) {
|
|
121
144
|
return (0, es_toolkit_1.uniq)((await (0, promise_map_1.default)(fileList, async (f) => {
|
|
@@ -129,6 +152,8 @@ async function normalizeInputFileList(fileList) {
|
|
|
129
152
|
}, (0, node_os_1.availableParallelism)())).flat());
|
|
130
153
|
}
|
|
131
154
|
/* #endregion */
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
155
|
+
;
|
|
156
|
+
(async () => {
|
|
157
|
+
console.log(await normalizeInputFileList(['@pf']));
|
|
158
|
+
console.log(await exports.PathFinder.getActiveTabDir());
|
|
159
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mac-helper",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"packageManager": "pnpm@
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"packageManager": "pnpm@11.1.3+sha512.c85357fe17ca12dd23dd7071822666dfd7e3cb76fe214e3370b5ea2fb34f2a231185509b63e717f3cd0acb38dd3f8d82bcd5e8172400ae678b70ea4fbed0896d",
|
|
5
5
|
"description": "useful helper for macOS",
|
|
6
|
-
"
|
|
7
|
-
"mac",
|
|
8
|
-
"helper",
|
|
9
|
-
"mac-helper"
|
|
10
|
-
],
|
|
6
|
+
"author": "magicdawn",
|
|
11
7
|
"license": "MIT",
|
|
12
8
|
"homepage": "https://github.com/magicdawn/mac-helper#readme",
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/magicdawn/mac-helper/issues"
|
|
15
|
-
},
|
|
16
9
|
"repository": {
|
|
17
10
|
"type": "git",
|
|
18
11
|
"url": "git+ssh://git@github.com/magicdawn/mac-helper.git"
|
|
19
12
|
},
|
|
20
|
-
"
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/magicdawn/mac-helper/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"mac",
|
|
18
|
+
"helper",
|
|
19
|
+
"mac-helper"
|
|
20
|
+
],
|
|
21
|
+
"main": "lib/index.js",
|
|
22
|
+
"types": "lib/index.d.ts",
|
|
21
23
|
"files": [
|
|
22
24
|
"lib/",
|
|
23
25
|
"src/"
|
|
24
26
|
],
|
|
25
|
-
"main": "lib/index.js",
|
|
26
|
-
"types": "lib/index.d.ts",
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"registry": "https://registry.npmjs.org"
|
|
29
29
|
},
|
|
@@ -39,38 +39,29 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@jxa/run": "^1.4.0",
|
|
42
|
-
"es-toolkit": "^1.
|
|
42
|
+
"es-toolkit": "^1.46.1",
|
|
43
43
|
"promise.map": "^1.1.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@jxa/global-type": "^1.4.0",
|
|
47
47
|
"@jxa/sdef-to-dts": "^1.4.0",
|
|
48
48
|
"@jxa/types": "^1.4.0",
|
|
49
|
-
"@magicdawn/eslint-config": "^1.6.
|
|
49
|
+
"@magicdawn/eslint-config": "^1.6.5",
|
|
50
50
|
"@magicdawn/prettier-config": "^0.1.0",
|
|
51
51
|
"@types/fs-extra": "^11.0.4",
|
|
52
|
-
"@types/node": "^25.
|
|
53
|
-
"@vitest/coverage-v8": "^4.
|
|
52
|
+
"@types/node": "^25.8.0",
|
|
53
|
+
"@vitest/coverage-v8": "^4.1.6",
|
|
54
54
|
"delay": "^7.0.0",
|
|
55
|
-
"eslint": "^
|
|
55
|
+
"eslint": "^10.4.0",
|
|
56
56
|
"eslint-config-prettier": "^10.1.8",
|
|
57
|
-
"fs-extra": "^11.3.
|
|
57
|
+
"fs-extra": "^11.3.5",
|
|
58
58
|
"husky": "^9.1.7",
|
|
59
59
|
"jxa-common-used": "^0.0.3",
|
|
60
|
-
"lint-staged": "^
|
|
61
|
-
"prettier": "^3.8.
|
|
60
|
+
"lint-staged": "^17.0.5",
|
|
61
|
+
"prettier": "^3.8.3",
|
|
62
62
|
"should": "^13.2.3",
|
|
63
|
-
"typescript": "^
|
|
64
|
-
"vitest": "^4.
|
|
65
|
-
},
|
|
66
|
-
"pnpm": {
|
|
67
|
-
"onlyBuiltDependencies": [
|
|
68
|
-
"@swc/core",
|
|
69
|
-
"core-js",
|
|
70
|
-
"es5-ext",
|
|
71
|
-
"esbuild",
|
|
72
|
-
"unrs-resolver"
|
|
73
|
-
]
|
|
63
|
+
"typescript": "^6.0.3",
|
|
64
|
+
"vitest": "^4.1.6"
|
|
74
65
|
},
|
|
75
66
|
"lint-staged": {
|
|
76
67
|
"*.{js,jsx,ts,tsx,less,md}": [
|
package/src/chrome.ts
CHANGED
package/src/dialog.ts
CHANGED
|
@@ -59,7 +59,7 @@ async function chooseFromList(
|
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
if (!selected) return
|
|
62
|
-
const label = selected[0]
|
|
62
|
+
const label = (selected as any)[0]
|
|
63
63
|
|
|
64
64
|
if (!usingOption) {
|
|
65
65
|
return label
|
|
@@ -129,3 +129,4 @@ async function chooseMultipleFromList(
|
|
|
129
129
|
// .then((selected) => {
|
|
130
130
|
// console.log(selected)
|
|
131
131
|
// })
|
|
132
|
+
// dialog.prompt('hello', 'world').then(console.log)
|
package/src/finder.ts
CHANGED
|
@@ -20,6 +20,7 @@ export const PathFinder = {
|
|
|
20
20
|
setSelected(filePaths: string[]) {
|
|
21
21
|
return PathFinder_setSelected(filePaths)
|
|
22
22
|
},
|
|
23
|
+
getActiveTabDir: PathFinder_getActiveTabDir,
|
|
23
24
|
}
|
|
24
25
|
export const Finder = {
|
|
25
26
|
allSelected() {
|
|
@@ -62,8 +63,7 @@ async function PathFinder_singleSelected(): Promise<string | undefined> {
|
|
|
62
63
|
}
|
|
63
64
|
const firstFilePath: string | undefined = await jxaRun(() => {
|
|
64
65
|
const app = Application<PathFinderType>('Path Finder')
|
|
65
|
-
|
|
66
|
-
return arr[0]
|
|
66
|
+
return (app.selection() || [])[0]?.posixPath()
|
|
67
67
|
})
|
|
68
68
|
return firstFilePath
|
|
69
69
|
}
|
|
@@ -74,6 +74,30 @@ async function PathFinder_setSelected(filePaths: string[]) {
|
|
|
74
74
|
app.select(filePaths)
|
|
75
75
|
}, filePaths)
|
|
76
76
|
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 获取 activeTab dir, 当没有 selection 时可用,
|
|
80
|
+
* 要求只能有一个 visible window, 从 jxa 这一层无法区分 window z-index
|
|
81
|
+
*/
|
|
82
|
+
async function PathFinder_getActiveTabDir(): Promise<string | undefined> {
|
|
83
|
+
if (!(await isAppRunning('Path Finder'))) return
|
|
84
|
+
|
|
85
|
+
const visibleWindowCount: number = await jxaRun(() => {
|
|
86
|
+
const app = Application<PathFinderType>('Path Finder')
|
|
87
|
+
return app.finderWindows.whose({ visible: true }).length
|
|
88
|
+
})
|
|
89
|
+
if (!visibleWindowCount) return
|
|
90
|
+
if (visibleWindowCount > 1) {
|
|
91
|
+
throw new Error('Multiple visible PathFinder window not supported in PathFinder_getActiveTabDir')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const dir: string = await jxaRun(() => {
|
|
95
|
+
const app = Application<PathFinderType>('Path Finder')
|
|
96
|
+
const w = app.finderWindows.whose({ visible: true })[0]
|
|
97
|
+
return w.target.posixPath()
|
|
98
|
+
})
|
|
99
|
+
return dir
|
|
100
|
+
}
|
|
77
101
|
/* #endregion */
|
|
78
102
|
|
|
79
103
|
/* #region Finder */
|
|
@@ -124,15 +148,15 @@ async function QSpace_allSelected() {
|
|
|
124
148
|
|
|
125
149
|
/* #region Top Level Helper */
|
|
126
150
|
export function isRepresentPF(file: string) {
|
|
127
|
-
return
|
|
151
|
+
return /^[@$]?pf$/i.test(file)
|
|
128
152
|
}
|
|
129
153
|
|
|
130
154
|
export function isRepresentQS(file: string) {
|
|
131
|
-
return
|
|
155
|
+
return /^[@$]?qs$/i.test(file)
|
|
132
156
|
}
|
|
133
157
|
|
|
134
158
|
/**
|
|
135
|
-
* 处理
|
|
159
|
+
* 处理 `@pf` `@qs`, ignore case
|
|
136
160
|
*/
|
|
137
161
|
export async function normalizeInputFileList(fileList: string[]) {
|
|
138
162
|
return uniq(
|
|
@@ -153,6 +177,7 @@ export async function normalizeInputFileList(fileList: string[]) {
|
|
|
153
177
|
}
|
|
154
178
|
/* #endregion */
|
|
155
179
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
180
|
+
;(async () => {
|
|
181
|
+
console.log(await normalizeInputFileList(['@pf']))
|
|
182
|
+
console.log(await PathFinder.getActiveTabDir())
|
|
183
|
+
})()
|