mac-helper 0.1.5 → 0.3.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/app.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAppRunning = void 0;
3
+ exports.isAppRunning = isAppRunning;
4
4
  const child_process_1 = require("child_process");
5
5
  /**
6
6
  * file path based process running detect.
@@ -22,5 +22,4 @@ async function isAppRunning(appName) {
22
22
  });
23
23
  });
24
24
  }
25
- exports.isAppRunning = isAppRunning;
26
25
  // isAppRunning('Visual Studio Code').then(console.log)
package/lib/chrome.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getChromeActiveTab = exports.Chrome = void 0;
3
+ exports.Chrome = void 0;
4
+ exports.getChromeActiveTab = getChromeActiveTab;
4
5
  const run_1 = require("@jxa/run");
5
6
  exports.Chrome = {
6
7
  async getActiveTab() {
@@ -19,5 +20,4 @@ async function getChromeActiveTab() {
19
20
  };
20
21
  });
21
22
  }
22
- exports.getChromeActiveTab = getChromeActiveTab;
23
23
  // getChromeActiveTab().then(console.log)
package/lib/dialog.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- import { StandardAdditions } from '@jxa/types';
1
+ import type { StandardAdditions } from '@jxa/types';
2
+ export declare const dialog: {
3
+ prompt: typeof prompt;
4
+ chooseFromList: typeof chooseFromList;
5
+ chooseMultipleFromList: typeof chooseMultipleFromList;
6
+ };
7
+ declare function prompt(label: string, defaultValue?: string): Promise<string>;
2
8
  type ChooseOption = {
3
9
  label: string;
4
10
  value: string;
5
11
  };
6
12
  declare function chooseFromList(list: string[] | ChooseOption[], options?: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter): Promise<string | undefined>;
7
13
  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
14
  export {};
package/lib/dialog.js CHANGED
@@ -2,6 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dialog = void 0;
4
4
  const run_1 = require("@jxa/run");
5
+ exports.dialog = {
6
+ prompt,
7
+ chooseFromList,
8
+ chooseMultipleFromList,
9
+ };
10
+ async function prompt(label, defaultValue = '') {
11
+ return ((await (0, run_1.run)((label) => {
12
+ const app = Application.currentApplication();
13
+ app.includeStandardAdditions = true;
14
+ const response = app.displayDialog(label, { defaultAnswer: '' });
15
+ return response.textReturned;
16
+ }, label)) || defaultValue);
17
+ }
5
18
  async function runOnCurrentApp(method, ...args) {
6
19
  return await (0, run_1.run)((method, ...args) => {
7
20
  const app = Application.currentApplication();
@@ -59,10 +72,6 @@ async function chooseMultipleFromList(list, options = {}) {
59
72
  return valArr;
60
73
  }
61
74
  }
62
- exports.dialog = {
63
- chooseFromList,
64
- chooseMultipleFromList,
65
- };
66
75
  // dialog.chooseFromList(['hello', 'world']).then((selected) => {
67
76
  // console.log(selected)
68
77
  // })
package/lib/finder.d.ts CHANGED
@@ -4,10 +4,12 @@
4
4
  export declare const PathFinder: {
5
5
  allSelected(): Promise<string[]>;
6
6
  singleSelected(): Promise<string | undefined>;
7
+ setSelected(filePaths: string[]): Promise<void>;
7
8
  };
8
9
  export declare const Finder: {
9
10
  allSelected(): Promise<string[]>;
10
11
  singleSelected(): Promise<string | undefined>;
12
+ setSelected(filePaths: string[]): Promise<void>;
11
13
  };
12
14
  export declare const QSpace: {
13
15
  allSelected(): Promise<string[]>;
@@ -17,7 +19,9 @@ export declare const QSpace: {
17
19
  * impls
18
20
  */
19
21
  export declare function getPathFinderSelected(): Promise<string[]>;
22
+ export declare function setPathFinderSelected(filePaths: string[]): Promise<void>;
20
23
  export declare function getFinderSelected(): Promise<string[]>;
24
+ export declare function setFinderSelected(filePaths: string[]): Promise<void>;
21
25
  export type QSpaceFileItem = {
22
26
  id: () => string;
23
27
  name: () => string;
package/lib/finder.js CHANGED
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getQSpaceSelected = exports.getFinderSelected = exports.getPathFinderSelected = exports.QSpace = exports.Finder = exports.PathFinder = void 0;
3
+ exports.QSpace = exports.Finder = exports.PathFinder = void 0;
4
+ exports.getPathFinderSelected = getPathFinderSelected;
5
+ exports.setPathFinderSelected = setPathFinderSelected;
6
+ exports.getFinderSelected = getFinderSelected;
7
+ exports.setFinderSelected = setFinderSelected;
8
+ exports.getQSpaceSelected = getQSpaceSelected;
4
9
  const run_1 = require("@jxa/run");
5
10
  const url_1 = require("url");
6
11
  const app_1 = require("./app");
@@ -14,6 +19,9 @@ exports.PathFinder = {
14
19
  async singleSelected() {
15
20
  return (await getPathFinderSelected())[0];
16
21
  },
22
+ async setSelected(filePaths) {
23
+ await setPathFinderSelected(filePaths);
24
+ },
17
25
  };
18
26
  exports.Finder = {
19
27
  async allSelected() {
@@ -22,6 +30,9 @@ exports.Finder = {
22
30
  async singleSelected() {
23
31
  return (await getFinderSelected())[0];
24
32
  },
33
+ async setSelected(filePaths) {
34
+ await setFinderSelected(filePaths);
35
+ },
25
36
  };
26
37
  exports.QSpace = {
27
38
  async allSelected() {
@@ -44,7 +55,12 @@ async function getPathFinderSelected() {
44
55
  });
45
56
  return filePaths;
46
57
  }
47
- exports.getPathFinderSelected = getPathFinderSelected;
58
+ async function setPathFinderSelected(filePaths) {
59
+ await (0, run_1.run)((filePaths) => {
60
+ const app = Application('Path Finder');
61
+ app.select(filePaths);
62
+ }, filePaths);
63
+ }
48
64
  async function getFinderSelected() {
49
65
  const urls = await (0, run_1.run)(() => {
50
66
  const app = Application('Finder');
@@ -53,7 +69,13 @@ async function getFinderSelected() {
53
69
  });
54
70
  return urls.map((u) => (0, url_1.fileURLToPath)(u));
55
71
  }
56
- exports.getFinderSelected = getFinderSelected;
72
+ async function setFinderSelected(filePaths) {
73
+ await (0, run_1.run)((filePaths) => {
74
+ const app = Application('Finder');
75
+ app.select(filePaths.map((f) => Path(f)));
76
+ app.activate();
77
+ }, filePaths);
78
+ }
57
79
  async function getQSpaceSelected() {
58
80
  if (!(await (0, app_1.isAppRunning)('QSpace Pro'))) {
59
81
  return [];
@@ -65,7 +87,6 @@ async function getQSpaceSelected() {
65
87
  });
66
88
  return urls.map((u) => (0, url_1.fileURLToPath)(u));
67
89
  }
68
- exports.getQSpaceSelected = getQSpaceSelected;
69
90
  // ;(async () => {
70
91
  // console.log(await getQSpaceSelected())
71
92
  // })()
package/lib/iterm.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.iTerm = exports.runInIterm = void 0;
3
+ exports.iTerm = void 0;
4
+ exports.runInIterm = runInIterm;
4
5
  const run_1 = require("@jxa/run");
5
6
  async function runInIterm(command, reuse = true) {
6
7
  await (0, run_1.run)((command, reuse) => {
@@ -11,7 +12,7 @@ async function runInIterm(command, reuse = true) {
11
12
  // reuse when possible
12
13
  if (reuse) {
13
14
  const session = app.currentWindow().currentSession();
14
- const isIdle = session.isAtShellPrompt();
15
+ const isIdle = session?.isAtShellPrompt();
15
16
  if (isIdle) {
16
17
  usingSession = session;
17
18
  }
@@ -27,7 +28,6 @@ async function runInIterm(command, reuse = true) {
27
28
  app.write(usingSession, { text: command });
28
29
  }, command, reuse);
29
30
  }
30
- exports.runInIterm = runInIterm;
31
31
  exports.iTerm = {
32
32
  run: runInIterm,
33
33
  runInIterm,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mac-helper",
3
- "version": "0.1.5",
3
+ "version": "0.3.0",
4
4
  "description": "useful helper for macOS",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -9,11 +9,12 @@
9
9
  "src/"
10
10
  ],
11
11
  "scripts": {
12
- "prepare": "husky install",
13
- "test": "vitest run --globals",
14
- "test:dev": "vitest --globals",
15
- "test-cover": "vitest run --globals --coverage",
12
+ "prepare": "husky",
13
+ "test": "vitest run --globals --testTimeout=30000",
14
+ "test:dev": "vitest --globals --testTimeout=30000",
15
+ "test-cover": "vitest run --globals --coverage --testTimeout=30000",
16
16
  "dev": "tsc -w --incremental",
17
+ "typecheck": "tsc --noEmit",
17
18
  "build": "rm -rf lib; rm tsconfig.tsbuildinfo; tsc",
18
19
  "prepublishOnly": "pnpm test && pnpm build"
19
20
  },
@@ -33,31 +34,31 @@
33
34
  },
34
35
  "homepage": "https://github.com/magicdawn/mac-helper#readme",
35
36
  "dependencies": {
36
- "@jxa/run": "^1.3.6"
37
+ "@jxa/run": "^1.4.0"
37
38
  },
38
39
  "devDependencies": {
39
- "@jxa/global-type": "^1.3.6",
40
- "@jxa/sdef-to-dts": "^1.3.6",
41
- "@jxa/types": "^1.3.6",
42
- "@magicdawn/prettier-config": "^0.0.3",
43
- "@swc/core": "1.5.7",
40
+ "@jxa/global-type": "^1.4.0",
41
+ "@jxa/sdef-to-dts": "^1.4.0",
42
+ "@jxa/types": "^1.4.0",
43
+ "@magicdawn/prettier-config": "^0.1.0",
44
+ "@swc/core": "1.11.24",
44
45
  "@types/fs-extra": "^11.0.4",
45
- "@types/mocha": "^10.0.6",
46
- "@types/node": "^20.12.12",
47
- "@typescript-eslint/eslint-plugin": "^7.10.0",
48
- "@typescript-eslint/parser": "^7.10.0",
49
- "@vitest/coverage-v8": "^1.6.0",
46
+ "@types/mocha": "^10.0.10",
47
+ "@types/node": "^22.15.17",
48
+ "@typescript-eslint/eslint-plugin": "^8.32.0",
49
+ "@typescript-eslint/parser": "^8.32.0",
50
+ "@vitest/coverage-v8": "^3.1.3",
50
51
  "delay": "^6.0.0",
51
- "eslint": "^9.3.0",
52
- "eslint-config-prettier": "^9.1.0",
53
- "fs-extra": "^11.2.0",
54
- "husky": "^9.0.11",
52
+ "eslint": "^9.26.0",
53
+ "eslint-config-prettier": "^10.1.5",
54
+ "fs-extra": "^11.3.0",
55
+ "husky": "^9.1.7",
55
56
  "jxa-common-used": "^0.0.3",
56
- "lint-staged": "^15.2.4",
57
- "prettier": "^3.2.5",
57
+ "lint-staged": "^16.0.0",
58
+ "prettier": "^3.5.3",
58
59
  "should": "^13.2.3",
59
- "typescript": "^5.4.5",
60
- "vitest": "^1.6.0"
60
+ "typescript": "^5.8.3",
61
+ "vitest": "^3.1.3"
61
62
  },
62
63
  "publishConfig": {
63
64
  "registry": "https://registry.npmjs.org"
@@ -67,5 +68,13 @@
67
68
  "prettier --write"
68
69
  ]
69
70
  },
70
- "packageManager": "pnpm@9.1.2+sha512.127dc83b9ea10c32be65d22a8efb4a65fb952e8fefbdfded39bdc3c97efc32d31b48b00420df2c1187ace28c921c902f0cb5a134a4d032b8b5295cbfa2c681e2"
71
+ "packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39",
72
+ "pnpm": {
73
+ "onlyBuiltDependencies": [
74
+ "@swc/core",
75
+ "core-js",
76
+ "es5-ext",
77
+ "esbuild"
78
+ ]
79
+ }
71
80
  }
package/src/dialog.ts CHANGED
@@ -1,5 +1,22 @@
1
1
  import { run } from '@jxa/run'
2
- import { StandardAdditions } from '@jxa/types'
2
+ import type { StandardAdditions } from '@jxa/types'
3
+
4
+ export const dialog = {
5
+ prompt,
6
+ chooseFromList,
7
+ chooseMultipleFromList,
8
+ }
9
+
10
+ async function prompt(label: string, defaultValue = ''): Promise<string> {
11
+ return (
12
+ (await run((label) => {
13
+ const app = Application.currentApplication()
14
+ app.includeStandardAdditions = true
15
+ const response = app.displayDialog(label, { defaultAnswer: '' })
16
+ return response.textReturned
17
+ }, label)) || defaultValue
18
+ )
19
+ }
3
20
 
4
21
  type AppMethod = 'chooseFromList'
5
22
 
@@ -12,7 +29,7 @@ async function runOnCurrentApp(method: AppMethod, ...args: any[]) {
12
29
  return app[method]?.(...args)
13
30
  },
14
31
  method,
15
- ...args
32
+ ...args,
16
33
  )
17
34
  }
18
35
 
@@ -20,7 +37,7 @@ type ChooseOption = { label: string; value: string }
20
37
 
21
38
  async function chooseFromList(
22
39
  list: string[] | ChooseOption[],
23
- options: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter = {}
40
+ options: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter = {},
24
41
  ): Promise<string | undefined> {
25
42
  let usingOption = false
26
43
  let showList: string[] = []
@@ -49,7 +66,7 @@ async function chooseFromList(
49
66
 
50
67
  async function chooseMultipleFromList(
51
68
  list: string[] | ChooseOption[],
52
- options: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter = {}
69
+ options: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter = {},
53
70
  ): Promise<string[]> {
54
71
  let usingOption = false
55
72
  let showList: string[] = []
@@ -71,17 +88,12 @@ async function chooseMultipleFromList(
71
88
  return selected as string[]
72
89
  } else {
73
90
  const valArr = (selected as string[]).map(
74
- (label) => (list as ChooseOption[]).find((item) => item.label === label)!.value
91
+ (label) => (list as ChooseOption[]).find((item) => item.label === label)!.value,
75
92
  )
76
93
  return valArr
77
94
  }
78
95
  }
79
96
 
80
- export const dialog = {
81
- chooseFromList,
82
- chooseMultipleFromList,
83
- }
84
-
85
97
  // dialog.chooseFromList(['hello', 'world']).then((selected) => {
86
98
  // console.log(selected)
87
99
  // })
package/src/finder.ts CHANGED
@@ -13,6 +13,9 @@ export const PathFinder = {
13
13
  async singleSelected(): Promise<string | undefined> {
14
14
  return (await getPathFinderSelected())[0]
15
15
  },
16
+ async setSelected(filePaths: string[]) {
17
+ await setPathFinderSelected(filePaths)
18
+ },
16
19
  }
17
20
  export const Finder = {
18
21
  async allSelected() {
@@ -21,6 +24,9 @@ export const Finder = {
21
24
  async singleSelected(): Promise<string | undefined> {
22
25
  return (await getFinderSelected())[0]
23
26
  },
27
+ async setSelected(filePaths: string[]) {
28
+ await setFinderSelected(filePaths)
29
+ },
24
30
  }
25
31
  export const QSpace = {
26
32
  async allSelected() {
@@ -46,6 +52,13 @@ export async function getPathFinderSelected() {
46
52
  return filePaths
47
53
  }
48
54
 
55
+ export async function setPathFinderSelected(filePaths: string[]) {
56
+ await jxaRun((filePaths: string[]) => {
57
+ const app = Application<PathFinderType>('Path Finder')
58
+ app.select(filePaths)
59
+ }, filePaths)
60
+ }
61
+
49
62
  export async function getFinderSelected() {
50
63
  const urls: string[] = await jxaRun(() => {
51
64
  const app = Application('Finder')
@@ -55,6 +68,14 @@ export async function getFinderSelected() {
55
68
  return urls.map((u) => fileURLToPath(u))
56
69
  }
57
70
 
71
+ export async function setFinderSelected(filePaths: string[]) {
72
+ await jxaRun((filePaths: string[]) => {
73
+ const app = Application('Finder')
74
+ app.select(filePaths.map((f) => Path(f)))
75
+ app.activate()
76
+ }, filePaths)
77
+ }
78
+
58
79
  // file item n [inh. item] : A file item.
59
80
  // properties
60
81
  // - id (text, r/o) : The unique identifier of the item.
package/src/iterm.ts CHANGED
@@ -13,7 +13,7 @@ export async function runInIterm(command: string, reuse = true) {
13
13
  // reuse when possible
14
14
  if (reuse) {
15
15
  const session: iTerm2.Session = app.currentWindow().currentSession()
16
- const isIdle = session.isAtShellPrompt()
16
+ const isIdle = session?.isAtShellPrompt()
17
17
  if (isIdle) {
18
18
  usingSession = session
19
19
  }
@@ -32,7 +32,7 @@ export async function runInIterm(command: string, reuse = true) {
32
32
  app.write(usingSession, { text: command })
33
33
  },
34
34
  command,
35
- reuse
35
+ reuse,
36
36
  )
37
37
  }
38
38