mac-helper 0.0.2 → 0.0.4
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/README.md +1 -1
- package/lib/dialog.d.ts +12 -0
- package/lib/dialog.js +93 -0
- package/lib/finder.d.ts +10 -0
- package/lib/finder.js +42 -0
- package/lib/index.d.ts +3 -8
- package/lib/index.js +18 -46
- package/lib/iterm.d.ts +5 -0
- package/lib/iterm.js +19 -0
- package/package.json +23 -18
- package/src/dialog.ts +114 -0
- package/src/finder.ts +43 -0
- package/src/index.ts +5 -47
- package/src/iterm.ts +19 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> useful helper for macOS
|
|
4
4
|
|
|
5
|
-
[](https://github.com/magicdawn/mac-helper/actions/workflows/ci.yml)
|
|
5
|
+
[](https://github.com/magicdawn/mac-helper/actions/workflows/ci.yml)
|
|
6
6
|
[](https://codecov.io/gh/magicdawn/mac-helper)
|
|
7
7
|
[](https://www.npmjs.com/package/mac-helper)
|
|
8
8
|
[](https://www.npmjs.com/package/mac-helper)
|
package/lib/dialog.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StandardAdditions } from '@jxa/types';
|
|
2
|
+
type ChooseOption = {
|
|
3
|
+
label: string;
|
|
4
|
+
value: string;
|
|
5
|
+
};
|
|
6
|
+
declare function chooseFromList(list: string[] | ChooseOption[], options?: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter): Promise<string | undefined>;
|
|
7
|
+
declare function chooseMultipleFromList(list: string[] | ChooseOption[], options?: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter): Promise<string[]>;
|
|
8
|
+
export declare const dialog: {
|
|
9
|
+
chooseFromList: typeof chooseFromList;
|
|
10
|
+
chooseMultipleFromList: typeof chooseMultipleFromList;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
package/lib/dialog.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dialog = void 0;
|
|
4
|
+
const run_1 = require("@jxa/run");
|
|
5
|
+
async function runOnCurrentApp(method, ...args) {
|
|
6
|
+
return await (0, run_1.run)((method, ...args) => {
|
|
7
|
+
const app = Application.currentApplication();
|
|
8
|
+
app.includeStandardAdditions = true;
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
return app[method]?.(...args);
|
|
11
|
+
}, method, ...args);
|
|
12
|
+
}
|
|
13
|
+
async function chooseFromList(list, options = {}) {
|
|
14
|
+
let usingOption = false;
|
|
15
|
+
let showList = [];
|
|
16
|
+
if (typeof list[0] === 'object') {
|
|
17
|
+
usingOption = true;
|
|
18
|
+
showList = list.map((l) => l.label);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
showList = list;
|
|
22
|
+
}
|
|
23
|
+
const selected = await runOnCurrentApp('chooseFromList', showList, {
|
|
24
|
+
multipleSelectionsAllowed: false,
|
|
25
|
+
...options,
|
|
26
|
+
});
|
|
27
|
+
if (!selected)
|
|
28
|
+
return;
|
|
29
|
+
const label = selected[0];
|
|
30
|
+
if (!usingOption) {
|
|
31
|
+
return label;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
const val = list.find((item) => item.label === label)?.value;
|
|
35
|
+
return val;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function chooseMultipleFromList(list, options = {}) {
|
|
39
|
+
let usingOption = false;
|
|
40
|
+
let showList = [];
|
|
41
|
+
if (typeof list[0] === 'object') {
|
|
42
|
+
usingOption = true;
|
|
43
|
+
showList = list.map((l) => l.label);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
showList = list;
|
|
47
|
+
}
|
|
48
|
+
const selected = await runOnCurrentApp('chooseFromList', showList, {
|
|
49
|
+
multipleSelectionsAllowed: true,
|
|
50
|
+
...options,
|
|
51
|
+
});
|
|
52
|
+
if (!selected)
|
|
53
|
+
return [];
|
|
54
|
+
if (!usingOption) {
|
|
55
|
+
return selected;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const valArr = selected.map((label) => list.find((item) => item.label === label).value);
|
|
59
|
+
return valArr;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.dialog = {
|
|
63
|
+
chooseFromList,
|
|
64
|
+
chooseMultipleFromList,
|
|
65
|
+
};
|
|
66
|
+
// dialog.chooseFromList(['hello', 'world']).then((selected) => {
|
|
67
|
+
// console.log(selected)
|
|
68
|
+
// })
|
|
69
|
+
// dialog
|
|
70
|
+
// .chooseFromList([
|
|
71
|
+
// { value: 'yes', label: '是吧~~~' },
|
|
72
|
+
// { value: 'halo', label: 'Halo 啊洒洒' },
|
|
73
|
+
// ])
|
|
74
|
+
// .then((selected) => {
|
|
75
|
+
// console.log(selected)
|
|
76
|
+
// })
|
|
77
|
+
// dialog
|
|
78
|
+
// .chooseMultipleFromList(
|
|
79
|
+
// [
|
|
80
|
+
// { value: 'yes', label: '是吧~~~' },
|
|
81
|
+
// { value: 'halo', label: 'Halo 啊洒洒' },
|
|
82
|
+
// ],
|
|
83
|
+
// {
|
|
84
|
+
// withTitle: 'title',
|
|
85
|
+
// withPrompt: 'prompt',
|
|
86
|
+
// cancelButtonName: '取消!',
|
|
87
|
+
// // @ts-ignore
|
|
88
|
+
// okButtonName: '酱紫吧~',
|
|
89
|
+
// }
|
|
90
|
+
// )
|
|
91
|
+
// .then((selected) => {
|
|
92
|
+
// console.log(selected)
|
|
93
|
+
// })
|
package/lib/finder.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function getPathFinderSelected(): Promise<string[]>;
|
|
2
|
+
export declare function getFinderSelected(): Promise<string[]>;
|
|
3
|
+
export declare const PathFinder: {
|
|
4
|
+
allSelected(): Promise<string[]>;
|
|
5
|
+
singleSelected(): Promise<string | undefined>;
|
|
6
|
+
};
|
|
7
|
+
export declare const Finder: {
|
|
8
|
+
allSelected(): Promise<string[]>;
|
|
9
|
+
singleSelected(): Promise<string | undefined>;
|
|
10
|
+
};
|
package/lib/finder.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Finder = exports.PathFinder = exports.getFinderSelected = exports.getPathFinderSelected = void 0;
|
|
4
|
+
const run_1 = require("@jxa/run");
|
|
5
|
+
const url_1 = require("url");
|
|
6
|
+
async function getPathFinderSelected() {
|
|
7
|
+
const filePaths = await (0, run_1.run)(() => {
|
|
8
|
+
const app = Application('Path Finder');
|
|
9
|
+
return (app.selection() || []).map((x) => x.posixPath());
|
|
10
|
+
});
|
|
11
|
+
return filePaths;
|
|
12
|
+
}
|
|
13
|
+
exports.getPathFinderSelected = getPathFinderSelected;
|
|
14
|
+
async function getFinderSelected() {
|
|
15
|
+
const urls = await (0, run_1.run)(() => {
|
|
16
|
+
const app = Application('Finder');
|
|
17
|
+
const selection = app.selection();
|
|
18
|
+
return (selection || []).map((x) => x.url());
|
|
19
|
+
});
|
|
20
|
+
return urls.map((u) => (0, url_1.fileURLToPath)(u));
|
|
21
|
+
}
|
|
22
|
+
exports.getFinderSelected = getFinderSelected;
|
|
23
|
+
exports.PathFinder = {
|
|
24
|
+
async allSelected() {
|
|
25
|
+
return getPathFinderSelected();
|
|
26
|
+
},
|
|
27
|
+
async singleSelected() {
|
|
28
|
+
return (await getPathFinderSelected())[0];
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
exports.Finder = {
|
|
32
|
+
async allSelected() {
|
|
33
|
+
return getFinderSelected();
|
|
34
|
+
},
|
|
35
|
+
async singleSelected() {
|
|
36
|
+
return (await getFinderSelected())[0];
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
// ;(async () => {
|
|
40
|
+
// console.log(await getPathFinderSelect())
|
|
41
|
+
// console.log(await getPathFinderSelects())
|
|
42
|
+
// })()
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export declare function getPathFinderSelects(): Promise<string[]>;
|
|
5
|
-
export declare const PathFinder: {
|
|
6
|
-
singleSelected(): Promise<string | null>;
|
|
7
|
-
allSelected(): Promise<string[]>;
|
|
8
|
-
};
|
|
1
|
+
export * from './finder';
|
|
2
|
+
export * from './iterm';
|
|
3
|
+
export * from './dialog';
|
package/lib/index.js
CHANGED
|
@@ -1,49 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/// <reference types='@jxa/global-type' />
|
|
3
|
+
/// <reference types='@jxa/types' />
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
4
17
|
};
|
|
5
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
require("
|
|
8
|
-
|
|
9
|
-
const applescript_1 = __importDefault(require("applescript"));
|
|
10
|
-
const promise_ify_1 = __importDefault(require("promise.ify"));
|
|
11
|
-
const SCRIPT_FI_SELECTION = `
|
|
12
|
-
tell application "Path Finder"
|
|
13
|
-
get POSIX path of (get item 1 of (get selection))
|
|
14
|
-
end tell
|
|
15
|
-
`;
|
|
16
|
-
async function deprecated_getFinderSelectionViaAppleScript() {
|
|
17
|
-
const result = (await (0, promise_ify_1.default)(applescript_1.default.execString, applescript_1.default)(SCRIPT_FI_SELECTION.trim()));
|
|
18
|
-
const url = result && result[0];
|
|
19
|
-
return url;
|
|
20
|
-
}
|
|
21
|
-
exports.deprecated_getFinderSelectionViaAppleScript = deprecated_getFinderSelectionViaAppleScript;
|
|
22
|
-
async function getPathFinderSelect() {
|
|
23
|
-
const filePath = await (0, run_1.run)(() => {
|
|
24
|
-
const app = Application('Path Finder');
|
|
25
|
-
return app.selection()?.[0]?.posixPath() ?? null;
|
|
26
|
-
});
|
|
27
|
-
return filePath;
|
|
28
|
-
}
|
|
29
|
-
exports.getPathFinderSelect = getPathFinderSelect;
|
|
30
|
-
async function getPathFinderSelects() {
|
|
31
|
-
const filePaths = await (0, run_1.run)(() => {
|
|
32
|
-
const app = Application('Path Finder');
|
|
33
|
-
return (app.selection() || []).map((x) => x?.posixPath());
|
|
34
|
-
});
|
|
35
|
-
return filePaths;
|
|
36
|
-
}
|
|
37
|
-
exports.getPathFinderSelects = getPathFinderSelects;
|
|
38
|
-
exports.PathFinder = {
|
|
39
|
-
singleSelected() {
|
|
40
|
-
return getPathFinderSelect();
|
|
41
|
-
},
|
|
42
|
-
allSelected() {
|
|
43
|
-
return getPathFinderSelects();
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
// ;(async () => {
|
|
47
|
-
// console.log(await getPathFinderSelect())
|
|
48
|
-
// console.log(await getPathFinderSelects())
|
|
49
|
-
// })()
|
|
19
|
+
__exportStar(require("./finder"), exports);
|
|
20
|
+
__exportStar(require("./iterm"), exports);
|
|
21
|
+
__exportStar(require("./dialog"), exports);
|
package/lib/iterm.d.ts
ADDED
package/lib/iterm.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.iTerm = exports.runInIterm = void 0;
|
|
4
|
+
const run_1 = require("@jxa/run");
|
|
5
|
+
async function runInIterm(command) {
|
|
6
|
+
await (0, run_1.run)((command) => {
|
|
7
|
+
const app = Application('iTerm');
|
|
8
|
+
app.includeStandardAdditions = true;
|
|
9
|
+
app.activate();
|
|
10
|
+
const tab = app.createTabWithDefaultProfile(app.currentWindow);
|
|
11
|
+
const sess = tab.currentSession;
|
|
12
|
+
app.write(sess, { text: command });
|
|
13
|
+
}, command);
|
|
14
|
+
}
|
|
15
|
+
exports.runInIterm = runInIterm;
|
|
16
|
+
exports.iTerm = {
|
|
17
|
+
run: runInIterm,
|
|
18
|
+
runInIterm,
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mac-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "useful helper for macOS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"test-cover": "nyc --reporter=lcov --reporter=text mocha",
|
|
15
15
|
"dev": "tsc -w --incremental",
|
|
16
16
|
"build": "rm -rf lib; rm tsconfig.tsbuildinfo; tsc",
|
|
17
|
-
"prepublishOnly": "pnpm build"
|
|
17
|
+
"prepublishOnly": "pnpm test && pnpm build"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -31,19 +31,30 @@
|
|
|
31
31
|
"url": "https://github.com/magicdawn/mac-helper/issues"
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/magicdawn/mac-helper#readme",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@jxa/run": "^1.3.6"
|
|
36
|
+
},
|
|
34
37
|
"devDependencies": {
|
|
38
|
+
"@jxa/global-type": "^1.3.6",
|
|
39
|
+
"@jxa/sdef-to-dts": "^1.3.6",
|
|
40
|
+
"@jxa/types": "^1.3.6",
|
|
35
41
|
"@magicdawn/prettier-config": "^0.0.2",
|
|
36
|
-
"@swc/core": "^1.3.
|
|
37
|
-
"@types/
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"eslint": "^
|
|
41
|
-
"eslint
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
42
|
+
"@swc/core": "^1.3.40",
|
|
43
|
+
"@types/fs-extra": "^11.0.1",
|
|
44
|
+
"@types/mocha": "^10.0.1",
|
|
45
|
+
"@types/node": "^18.15.3",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
47
|
+
"@typescript-eslint/parser": "^5.55.0",
|
|
48
|
+
"delay": "^5.0.0",
|
|
49
|
+
"eslint": "^8.36.0",
|
|
50
|
+
"eslint-config-prettier": "^8.7.0",
|
|
51
|
+
"fs-extra": "^11.1.0",
|
|
52
|
+
"husky": "^8.0.3",
|
|
53
|
+
"jxa-common-used": "^0.0.2",
|
|
54
|
+
"lint-staged": "^13.2.0",
|
|
55
|
+
"mocha": "^10.2.0",
|
|
45
56
|
"nyc": "^15.1.0",
|
|
46
|
-
"prettier": "^2.
|
|
57
|
+
"prettier": "^2.8.4",
|
|
47
58
|
"should": "^13.2.3",
|
|
48
59
|
"typescript": "^4.9.5"
|
|
49
60
|
},
|
|
@@ -55,11 +66,5 @@
|
|
|
55
66
|
"*.{js,jsx,ts,tsx,less,md}": [
|
|
56
67
|
"prettier --write"
|
|
57
68
|
]
|
|
58
|
-
},
|
|
59
|
-
"dependencies": {
|
|
60
|
-
"@jxa/global-type": "^1.3.6",
|
|
61
|
-
"@jxa/run": "^1.3.6",
|
|
62
|
-
"applescript": "^1.0.0",
|
|
63
|
-
"promise.ify": "^0.4.0"
|
|
64
69
|
}
|
|
65
70
|
}
|
package/src/dialog.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { run } from '@jxa/run'
|
|
2
|
+
import { StandardAdditions } from '@jxa/types'
|
|
3
|
+
|
|
4
|
+
type AppMethod = 'chooseFromList'
|
|
5
|
+
|
|
6
|
+
async function runOnCurrentApp(method: AppMethod, ...args: any[]) {
|
|
7
|
+
return await run(
|
|
8
|
+
(method: AppMethod, ...args: any[]) => {
|
|
9
|
+
const app = Application.currentApplication()
|
|
10
|
+
app.includeStandardAdditions = true
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
return app[method]?.(...args)
|
|
13
|
+
},
|
|
14
|
+
method,
|
|
15
|
+
...args
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type ChooseOption = { label: string; value: string }
|
|
20
|
+
|
|
21
|
+
async function chooseFromList(
|
|
22
|
+
list: string[] | ChooseOption[],
|
|
23
|
+
options: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter = {}
|
|
24
|
+
): Promise<string | undefined> {
|
|
25
|
+
let usingOption = false
|
|
26
|
+
let showList: string[] = []
|
|
27
|
+
if (typeof list[0] === 'object') {
|
|
28
|
+
usingOption = true
|
|
29
|
+
showList = (list as ChooseOption[]).map((l) => l.label)
|
|
30
|
+
} else {
|
|
31
|
+
showList = list as string[]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const selected = await runOnCurrentApp('chooseFromList', showList, {
|
|
35
|
+
multipleSelectionsAllowed: false,
|
|
36
|
+
...options,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
if (!selected) return
|
|
40
|
+
const label = selected[0]
|
|
41
|
+
|
|
42
|
+
if (!usingOption) {
|
|
43
|
+
return label
|
|
44
|
+
} else {
|
|
45
|
+
const val = (list as ChooseOption[]).find((item) => item.label === label)?.value
|
|
46
|
+
return val
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function chooseMultipleFromList(
|
|
51
|
+
list: string[] | ChooseOption[],
|
|
52
|
+
options: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter = {}
|
|
53
|
+
): Promise<string[]> {
|
|
54
|
+
let usingOption = false
|
|
55
|
+
let showList: string[] = []
|
|
56
|
+
if (typeof list[0] === 'object') {
|
|
57
|
+
usingOption = true
|
|
58
|
+
showList = (list as ChooseOption[]).map((l) => l.label)
|
|
59
|
+
} else {
|
|
60
|
+
showList = list as string[]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const selected = await runOnCurrentApp('chooseFromList', showList, {
|
|
64
|
+
multipleSelectionsAllowed: true,
|
|
65
|
+
...options,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
if (!selected) return []
|
|
69
|
+
|
|
70
|
+
if (!usingOption) {
|
|
71
|
+
return selected as string[]
|
|
72
|
+
} else {
|
|
73
|
+
const valArr = (selected as string[]).map(
|
|
74
|
+
(label) => (list as ChooseOption[]).find((item) => item.label === label)!.value
|
|
75
|
+
)
|
|
76
|
+
return valArr
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const dialog = {
|
|
81
|
+
chooseFromList,
|
|
82
|
+
chooseMultipleFromList,
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// dialog.chooseFromList(['hello', 'world']).then((selected) => {
|
|
86
|
+
// console.log(selected)
|
|
87
|
+
// })
|
|
88
|
+
|
|
89
|
+
// dialog
|
|
90
|
+
// .chooseFromList([
|
|
91
|
+
// { value: 'yes', label: '是吧~~~' },
|
|
92
|
+
// { value: 'halo', label: 'Halo 啊洒洒' },
|
|
93
|
+
// ])
|
|
94
|
+
// .then((selected) => {
|
|
95
|
+
// console.log(selected)
|
|
96
|
+
// })
|
|
97
|
+
|
|
98
|
+
// dialog
|
|
99
|
+
// .chooseMultipleFromList(
|
|
100
|
+
// [
|
|
101
|
+
// { value: 'yes', label: '是吧~~~' },
|
|
102
|
+
// { value: 'halo', label: 'Halo 啊洒洒' },
|
|
103
|
+
// ],
|
|
104
|
+
// {
|
|
105
|
+
// withTitle: 'title',
|
|
106
|
+
// withPrompt: 'prompt',
|
|
107
|
+
// cancelButtonName: '取消!',
|
|
108
|
+
// // @ts-ignore
|
|
109
|
+
// okButtonName: '酱紫吧~',
|
|
110
|
+
// }
|
|
111
|
+
// )
|
|
112
|
+
// .then((selected) => {
|
|
113
|
+
// console.log(selected)
|
|
114
|
+
// })
|
package/src/finder.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { run as jxaRun } from '@jxa/run'
|
|
2
|
+
import { type PathFinder as PathFinderType } from 'jxa-common-used'
|
|
3
|
+
import { fileURLToPath } from 'url'
|
|
4
|
+
|
|
5
|
+
export async function getPathFinderSelected() {
|
|
6
|
+
const filePaths: string[] = await jxaRun(() => {
|
|
7
|
+
const app = Application<PathFinderType>('Path Finder')
|
|
8
|
+
return (app.selection() || []).map((x) => x.posixPath())
|
|
9
|
+
})
|
|
10
|
+
return filePaths
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function getFinderSelected() {
|
|
14
|
+
const urls: string[] = await jxaRun(() => {
|
|
15
|
+
const app = Application('Finder')
|
|
16
|
+
const selection = app.selection()
|
|
17
|
+
return (selection || []).map((x) => x.url())
|
|
18
|
+
})
|
|
19
|
+
return urls.map((u) => fileURLToPath(u))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const PathFinder = {
|
|
23
|
+
async allSelected() {
|
|
24
|
+
return getPathFinderSelected()
|
|
25
|
+
},
|
|
26
|
+
async singleSelected(): Promise<string | undefined> {
|
|
27
|
+
return (await getPathFinderSelected())[0]
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const Finder = {
|
|
32
|
+
async allSelected() {
|
|
33
|
+
return getFinderSelected()
|
|
34
|
+
},
|
|
35
|
+
async singleSelected(): Promise<string | undefined> {
|
|
36
|
+
return (await getFinderSelected())[0]
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ;(async () => {
|
|
41
|
+
// console.log(await getPathFinderSelect())
|
|
42
|
+
// console.log(await getPathFinderSelects())
|
|
43
|
+
// })()
|
package/src/index.ts
CHANGED
|
@@ -1,48 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import AppleScript from 'applescript'
|
|
4
|
-
import pify from 'promise.ify'
|
|
1
|
+
/// <reference types='@jxa/global-type' />
|
|
2
|
+
/// <reference types='@jxa/types' />
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
end tell
|
|
10
|
-
`
|
|
11
|
-
export async function deprecated_getFinderSelectionViaAppleScript() {
|
|
12
|
-
const result = (await pify(
|
|
13
|
-
AppleScript.execString,
|
|
14
|
-
AppleScript
|
|
15
|
-
)(SCRIPT_FI_SELECTION.trim())) as string[]
|
|
16
|
-
const url = result && result[0]
|
|
17
|
-
return url
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export async function getPathFinderSelect() {
|
|
21
|
-
const filePath: string | null = await jxaRun(() => {
|
|
22
|
-
const app = Application('Path Finder')
|
|
23
|
-
return app.selection()?.[0]?.posixPath() ?? null
|
|
24
|
-
})
|
|
25
|
-
return filePath
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function getPathFinderSelects() {
|
|
29
|
-
const filePaths: string[] = await jxaRun(() => {
|
|
30
|
-
const app = Application('Path Finder')
|
|
31
|
-
return (app.selection() || []).map((x: any) => x?.posixPath())
|
|
32
|
-
})
|
|
33
|
-
return filePaths
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const PathFinder = {
|
|
37
|
-
singleSelected() {
|
|
38
|
-
return getPathFinderSelect()
|
|
39
|
-
},
|
|
40
|
-
allSelected() {
|
|
41
|
-
return getPathFinderSelects()
|
|
42
|
-
},
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// ;(async () => {
|
|
46
|
-
// console.log(await getPathFinderSelect())
|
|
47
|
-
// console.log(await getPathFinderSelects())
|
|
48
|
-
// })()
|
|
4
|
+
export * from './finder'
|
|
5
|
+
export * from './iterm'
|
|
6
|
+
export * from './dialog'
|
package/src/iterm.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { run } from '@jxa/run'
|
|
2
|
+
import { iTerm2 } from 'jxa-common-used'
|
|
3
|
+
|
|
4
|
+
export async function runInIterm(command: string) {
|
|
5
|
+
await run((command) => {
|
|
6
|
+
const app = Application<iTerm2>('iTerm')
|
|
7
|
+
app.includeStandardAdditions = true
|
|
8
|
+
app.activate()
|
|
9
|
+
|
|
10
|
+
const tab = app.createTabWithDefaultProfile(app.currentWindow)
|
|
11
|
+
const sess = tab.currentSession
|
|
12
|
+
app.write(sess, { text: command })
|
|
13
|
+
}, command)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const iTerm = {
|
|
17
|
+
run: runInIterm,
|
|
18
|
+
runInIterm,
|
|
19
|
+
}
|