📌  相关文章
📜  运行一个 applescript - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:23.805000             🧑  作者: Mango

代码示例1
on run {input, parameters}
    tell application "Finder"
        --get the selected file
        set selectedItem to (item 1 of (get selection))

        --get location info (folder:file format)
        set fileLocation to (selectedItem as alias) as string

        --replace : with / with subroutine
        set the semifinal to my replace_chars(fileLocation, ":", "/")

        --remove Macintosh HD with subroutine
        set the theFinal to my replace_chars(semifinal, "Macintosh HD", "")
    end tell
    do shell script "osascript " & "\"" & theFinal & "\""
    return input
end run

on replace_chars(this_text, search_string, replacement_string)
    set AppleScript's text item delimiters to the search_string
    set the item_list to every text item of this_text
    set AppleScript's text item delimiters to the replacement_string
    set this_text to the item_list as string
    set AppleScript's text item delimiters to ""
    return this_text
end replace_chars