Friday, October 22, 2021

#1 2021-07-05 12:27:25 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 901

Automator Service to comment/uncomments lines in AS

Simple Automator Service that take text as input (AppleScript) and make a comment or uncomment. Copy the script below to Run AppleScript Action and set text as input. (Quick Action)

The Service could be run from any Editor of your like, or easily be changed to any programming or scripting language. The script is based on multiply lines of comments or uncomments.

on run {input, parameters}
    set selectedText to item 1 of input as text
    set outputText to {}
    if selectedText contains "(*" then
        repeat with i from 2 to ((count paragraphs of selectedText) - 1)
            if (count characters of paragraph i of selectedText as text) is 1 then
                copy "" to end of outputText
            else
                copy (characters 2 thru -1 of paragraph i of selectedText as text) to end of outputText
            end if
        end repeat
    else
        copy "(**" to end of outputText
        repeat with i from 1 to (count paragraphs of selectedText)
            copy tab & paragraph i of selectedText to end of outputText
        end repeat
        copy "*)" to end of outputText
    end if
    set AppleScript's text item delimiters to {linefeed}
    set outputText to outputText as text
    set AppleScript's text item delimiters to {}
    return outputText
end run


if you are the expert, who will you call if its not your imagination.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)