Text ext(文本、字符修剪、方向) --“开始”、“结束”、“两者” 将TrimLength设置为要修剪的角色的长度 --修剪开始 如果方向在{“开始”,“两个”},则 在文本以字符开头时重复此操作 尝试 将文本设置为字符串形式的文本的字符(字符串长度+1)到

Text ext(文本、字符修剪、方向) --“开始”、“结束”、“两者” 将TrimLength设置为要修剪的角色的长度 --修剪开始 如果方向在{“开始”,“两个”},则 在文本以字符开头时重复此操作 尝试 将文本设置为字符串形式的文本的字符(字符串长度+1)到,text,applescript,Text,Applescript,ext(文本、字符修剪、方向) --“开始”、“结束”、“两者” 将TrimLength设置为要修剪的角色的长度 --修剪开始 如果方向在{“开始”,“两个”},则 在文本以字符开头时重复此操作 尝试 将文本设置为字符串形式的文本的字符(字符串长度+1)到-1 论错误 --文本只包含修剪字符 返回“” 结束尝试 结束重复 如果结束 --修剪结束 如果trimDirection在{“end”,“both”}中,则 在文本以字符结束时重复此操作 尝试 将文本设置为字符串形式文本的字符1到-(字符串长

ext(文本、字符修剪、方向) --“开始”、“结束”、“两者” 将TrimLength设置为要修剪的角色的长度 --修剪开始 如果方向在{“开始”,“两个”},则 在文本以字符开头时重复此操作 尝试 将文本设置为字符串形式的文本的字符(字符串长度+1)到-1 论错误 --文本只包含修剪字符 返回“” 结束尝试 结束重复 如果结束 --修剪结束 如果trimDirection在{“end”,“both”}中,则 在文本以字符结束时重复此操作 尝试 将文本设置为字符串形式文本的字符1到-(字符串长度+1) 论错误 --文本只包含修剪字符 返回“” 结束尝试 结束重复 如果结束 返回文本 结束文本
谢谢,很简单。奇怪的是,我没有意识到按键组合会产生我想要的结果。如果你只是想给文本编辑宏分配快捷方式,这通常是一个更好的选择。
(*
Save this as an application
Right click the application and select "Show Package Contents"
Add this to Info.plist between <dict> and </dict>

<key>LSBackgroundOnly</key>
    <true/>

launch the application with spotlight (command space)
*)

tell application "System Events"
    key code 123 using {command down, shift down}
    key code 124 using {command down, shift down}
    keystroke "c" using {command down}
end tell
{
/* Remap Home/End keys to be like Windows */
"\UF729" = "moveToBeginningOfLine:"; /* Home */
"\UF72B" = "moveToEndOfLine:"; /* End */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */

/* page up/down and move the caret like Windows*/
"\UF72C"  = "pageUp:";
"\UF72D"  = "pageDown:";

/* Option Home/End keys Beginning/End of Document like Mac */
"~\UF729" = "moveToBeginningOfDocument:"; /* Ctrl + Home */
"~\UF72B" = "moveToEndOfDocument:"; /* Ctrl + End */
"$~\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Ctrl + Home */
"$~\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Ctrl + End */

/* Ctrl Home/End keys Beginning/End of Document like Mac */
"^\UF729" = "moveToBeginningOfDocument:"; /* Ctrl + Home */
"^\UF72B" = "moveToEndOfDocument:"; /* Ctrl + End */
"$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Ctrl + Home */
"$^\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Ctrl + End */
}




use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use application "Xcode-beta"

global appName

set appName to "Xcode-beta"

-- for some reason pressing command+C only works ever other time without this
--delay 0.1

tell application appName
    activate

    set theDocuments to every source document

    -- exit if no source documents are found
    if theDocuments is equal to {} then
        -- copy command must go somewhere i.e. the user might have copied an Icon.
        tell application "System Events" to keystroke "c" using {command down}
        do shell script "logger -t 'AS DEBUG' " & "Applescript CopyCurrentLine - exit if no source documents are found"

        return -- exit script
    end if

    -- Note:
    -- window 1 is where source documents live
    -- It sure would've been nice if window contained a reference to its source document but it doesn't

    -- if window has been edited its' name ends with " — Edited" and it needs to be trimed off
    set windowName to name of window 1
    if windowName ends with " — Edited" then
        set windowName to my trimText(windowName, " — Edited", "end")
    end if

    -- try to find the windows' current source document by matching window name to source document name
    repeat with theDoc in theDocuments
        set theDocName to name of theDoc

        if theDocName is equal to windowName then
            exit repeat -- found the document
        else
            set theDocName to "" -- didn't find the document
        end if
    end repeat

    -- exit if the window is not a source document
    if theDocName is equal to "" then
        -- copy command must go somewhere i.e. the user might have copied an Icon.
        tell application "System Events" to keystroke "c" using {command down}
        do shell script "logger -t 'AS DEBUG' " & "Applescript CopyCurrentLine - exit if the window is not a source document"

        return -- exit script
    end if

    --set theDoc to last source document
    set docText to the text of theDoc

    -- get location of selected text
    set {startPos, endPos} to selected character range of theDoc

    if (my isSelectedTextRangeEmpty(theDoc)) then
        -- select current line
        -- I set a keybinding in Xcode so Command+L would call the Command 'Select Line'
        tell application "System Events" to keystroke "l" using {command down}
    end if

    -- copy the selection to the clipboard
    set selectedText to my getSelectedText(theDoc, docText)

    -- restore insertion point to original location
    set selected character range of theDoc to {startPos, endPos}

    set the clipboard to selectedText
end tell

on getSelectedText(theContainer, docText)
    -- get the selected text
    set {startPos, endPos} to selected character range of theContainer

    if {endPos < startPos} then
        return ""
    else
        return (text startPos thru endPos) in docText
    end if
end getSelectedText

on isSelectedTextRangeEmpty(theContainer)
    set selectedCharacterRange to selected character range of theContainer
    set {startPos, endPos} to selectedCharacterRange

    if {endPos < startPos} or ¬
        (selectedCharacterRange is equal to {}) or ¬
        (length of selectedCharacterRange is equal to 0) then
        return true
    else
        return false
    end if
end isSelectedTextRangeEmpty

on trimText(theText, theCharactersToTrim, theTrimDirection)
    -- "beginning", "end", "both"
    set theTrimLength to the length of the theCharactersToTrim
    -- TRIM BEGINNING
    if the theTrimDirection is in {"beginning", "both"} then
        repeat while theText begins with the theCharactersToTrim
            try
                set theText to characters (theTrimLength + 1) thru -1 of theText as string
            on error
                -- the text contains nothing but the trim characters
                return ""
            end try
        end repeat
    end if
    -- TRIM ENDING
    if the theTrimDirection is in {"end", "both"} then
        repeat while theText ends with the theCharactersToTrim
            try
                set theText to characters 1 thru -(theTrimLength + 1) of theText as string
            on error
                -- the text contains nothing but the trim characters
                return ""
            end try
        end repeat
    end if
    return theText
end trimText