Skip to content

Instantly share code, notes, and snippets.

@OKsign
Created May 18, 2018 12:06
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 OKsign/85978e8e28f7e89a15091c08ed5f0dc2 to your computer and use it in GitHub Desktop.
Save OKsign/85978e8e28f7e89a15091c08ed5f0dc2 to your computer and use it in GitHub Desktop.
-- user options
set mNumber to "" -- "show" or ""
set mBlankLine to "" -- "show" or ""
-- end of user options
try
delay 0.5
set copT to the clipboard
set AppleScript's text item delimiters to {return}
set aList to every text item of copT
set a2List to {}
repeat with i from 1 to count aList
if item i of aList is not "" then
copy item i of aList to the end of a2List
end if
end repeat
set arrPos to {}
repeat with i from 1 to count a2List
if item i of a2List contains "-->" then
copy i to the end of arrPos
end if
end repeat
delay 0.05
set bList to {}
repeat with i from 1 to (count arrPos) - 1
if mNumber is "show" then
copy item ((item i of arrPos) - 1) of a2List & "
" to the end of bList
end if
set x to 0
repeat with n from ((item i of arrPos) + 1) to ((item (i + 1) of arrPos) - 2)
set y to 1
set x to x + y
delay 0.02
if x = 1 then
copy item n of a2List to the end of bList
else
copy "
" & item n of a2List to the end of bList
end if
end repeat
-- blank line between sub
if mBlankLine is "show" then
copy "
" to the end of bList
-- end blank line between sub
else
copy "
" to the end of bList
end if
end repeat
delay 0.02
set lineLeft to (count a2List) - (last item of arrPos)
if lineLeft = 1 then
if mNumber is "show" then
copy item ((last item of arrPos) - 1) of a2List & "
" to the end of bList
end if
copy item ((last item of arrPos) + 1) of a2List to the end of bList
end if
if lineLeft > 1 then
if mNumber is "show" then
copy item ((last item of arrPos) - 1) of a2List & "
" to the end of bList
end if
repeat with i from 1 to ((count a2List) - (last item of arrPos))
copy item ((last item of arrPos) + i) of a2List & "
" to the end of bList
end repeat
end if
-- search replace
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to ", " -- search
set the item_list to every text item of bList -- original text
delay 0.04
set AppleScript's text item delimiters to the "" -- replace
set mText to the item_list as string
set AppleScript's text item delimiters to prevTIDs
delay 1
set the clipboard to mText
delay 1
display notification "Done!" with title "Script 9"
end try
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment