Skip to content

Instantly share code, notes, and snippets.

@myui
Last active July 2, 2019 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myui/6fa2abce6b54b0ca8d8ce45b2d6138af to your computer and use it in GitHub Desktop.
Save myui/6fa2abce6b54b0ca8d8ce45b2d6138af to your computer and use it in GitHub Desktop.
set my_coment to "#" --コメント文字
tell application "mi"
tell document 1
set p_count to (count paragraphs of selection object 1)
set start_p to index of paragraph 1 of selection object 1
set end_p to start_p + p_count - 1
repeat with i from start_p to end_p
set tmp_str to quoted form of (paragraph i as Unicode text)
try
do shell script "echo " & tmp_str & " | grep -E '^[[:space:]]*" & my_coment & "'"
set paragraph i to (do shell script "echo " & tmp_str & "| sed -e 's/^\\([[:space:]]*\\)" & my_coment & "/\\1/;'") & return
on error errMsg number errNum
if errNum is 1 then
set paragraph i to (do shell script "echo " & tmp_str & "| sed -e 's/^/" & my_coment & "/;'") & return
else
activate
display dialog "Error!"
end if
end try
end repeat
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment