mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-09-24 04:53:31 +08:00
MacOS专区,新增访达管理,支持获取选中项,获取打开的路径,显示隐藏文件,获取窗口列表,激活窗口
This commit is contained in:
@@ -1,76 +1,47 @@
|
||||
module.exports = {
|
||||
// 获取选中项
|
||||
getSelection: async function () {
|
||||
return await quickcommand.runAppleScript(`
|
||||
const result = await quickcommand.runAppleScript(`
|
||||
tell application "Finder"
|
||||
set selectedItems to selection
|
||||
set itemList to {}
|
||||
repeat with theItem in selectedItems
|
||||
set end of itemList to {
|
||||
name: name of theItem,
|
||||
path: POSIX path of (theItem as alias),
|
||||
kind: kind of theItem,
|
||||
size: size of theItem,
|
||||
created: creation date of theItem,
|
||||
modified: modification date of theItem
|
||||
}
|
||||
set json to "["
|
||||
repeat with i from 1 to count of selectedItems
|
||||
set theItem to item i of selectedItems
|
||||
set json to json & "{"
|
||||
set json to json & "\\"name\\":\\"" & name of theItem & "\\","
|
||||
set json to json & "\\"path\\":\\"" & POSIX path of (theItem as alias) & "\\","
|
||||
set json to json & "\\"kind\\":\\"" & kind of theItem & "\\","
|
||||
set json to json & "\\"size\\":" & size of theItem & ","
|
||||
set json to json & "\\"created\\":\\"" & creation date of theItem & "\\","
|
||||
set json to json & "\\"modified\\":\\"" & modification date of theItem & "\\""
|
||||
set json to json & "}"
|
||||
if i < count of selectedItems then
|
||||
set json to json & ","
|
||||
end if
|
||||
end repeat
|
||||
return itemList
|
||||
set json to json & "]"
|
||||
return json
|
||||
end tell
|
||||
`);
|
||||
return JSON.parse(result);
|
||||
},
|
||||
|
||||
// 获取当前文件夹
|
||||
getCurrentFolder: async function () {
|
||||
return await quickcommand.runAppleScript(`
|
||||
const result = await quickcommand.runAppleScript(`
|
||||
tell application "Finder"
|
||||
set currentFolder to (target of front window) as alias
|
||||
return {
|
||||
name: name of currentFolder,
|
||||
path: POSIX path of currentFolder,
|
||||
kind: kind of currentFolder,
|
||||
created: creation date of currentFolder,
|
||||
modified: modification date of currentFolder
|
||||
}
|
||||
end tell
|
||||
`);
|
||||
},
|
||||
|
||||
// 新建文件夹
|
||||
newFolder: async function (name) {
|
||||
return await quickcommand.runAppleScript(`
|
||||
tell application "Finder"
|
||||
set currentFolder to (target of front window) as alias
|
||||
make new folder at currentFolder with properties {name:"${name}"}
|
||||
end tell
|
||||
`);
|
||||
},
|
||||
|
||||
// 移到废纸篓
|
||||
moveToTrash: async function () {
|
||||
return await quickcommand.runAppleScript(`
|
||||
tell application "Finder"
|
||||
delete selection
|
||||
end tell
|
||||
`);
|
||||
},
|
||||
|
||||
// 清空废纸篓
|
||||
emptyTrash: async function () {
|
||||
return await quickcommand.runAppleScript(`
|
||||
tell application "Finder"
|
||||
empty trash
|
||||
end tell
|
||||
`);
|
||||
},
|
||||
|
||||
// 显示包内容
|
||||
showPackageContents: async function (path) {
|
||||
return await quickcommand.runAppleScript(`
|
||||
tell application "Finder"
|
||||
open package folder "${path}"
|
||||
set json to "{"
|
||||
set json to json & "\\"name\\":\\"" & name of currentFolder & "\\","
|
||||
set json to json & "\\"path\\":\\"" & POSIX path of currentFolder & "\\","
|
||||
set json to json & "\\"kind\\":\\"" & kind of currentFolder & "\\","
|
||||
set json to json & "\\"created\\":\\"" & creation date of currentFolder & "\\","
|
||||
set json to json & "\\"modified\\":\\"" & modification date of currentFolder & "\\""
|
||||
set json to json & "}"
|
||||
return json
|
||||
end tell
|
||||
`);
|
||||
return JSON.parse(result);
|
||||
},
|
||||
|
||||
// 设置显示隐藏文件
|
||||
@@ -81,29 +52,38 @@ module.exports = {
|
||||
`);
|
||||
},
|
||||
|
||||
// 设置显示路径栏
|
||||
setShowPathbar: async function (show) {
|
||||
return await quickcommand.runAppleScript(`
|
||||
// 获取窗口列表
|
||||
getWindows: async function () {
|
||||
const result = await quickcommand.runAppleScript(`
|
||||
tell application "Finder"
|
||||
set ShowPathbar to ${show}
|
||||
set windowList to every window
|
||||
set json to "["
|
||||
repeat with i from 1 to count of windowList
|
||||
set theWindow to item i of windowList
|
||||
set json to json & "{"
|
||||
set json to json & "\\"name\\":\\"" & name of theWindow & "\\","
|
||||
set json to json & "\\"index\\":" & index of theWindow & ","
|
||||
set json to json & "\\"bounds\\":\\"" & bounds of theWindow & "\\","
|
||||
set json to json & "\\"target\\":\\"" & POSIX path of (target of theWindow as alias) & "\\""
|
||||
set json to json & "}"
|
||||
if i < count of windowList then
|
||||
set json to json & ","
|
||||
end if
|
||||
end repeat
|
||||
set json to json & "]"
|
||||
return json
|
||||
end tell
|
||||
`);
|
||||
return JSON.parse(result);
|
||||
},
|
||||
|
||||
// 设置显示状态栏
|
||||
setShowStatusBar: async function (show) {
|
||||
// 激活指定窗口
|
||||
activateWindow: async function (index) {
|
||||
return await quickcommand.runAppleScript(`
|
||||
tell application "Finder"
|
||||
set StatusBar to ${show}
|
||||
end tell
|
||||
`);
|
||||
},
|
||||
|
||||
// 设置显示预览面板
|
||||
setShowPreviewPane: async function (show) {
|
||||
return await quickcommand.runAppleScript(`
|
||||
tell application "Finder"
|
||||
set PreviewPaneIsVisible to ${show}
|
||||
activate
|
||||
set theWindow to window ${index}
|
||||
set index of theWindow to 1
|
||||
end tell
|
||||
`);
|
||||
},
|
||||
|
Reference in New Issue
Block a user