Thanks, for all inputs… StefanK and technomorph, I will check it out…
I did some fast script in early version and not final. (This ex needs Script Editor)
property fileComments : POSIX path of (path to desktop) & "Proj/comments.txt"
set theRead to read fileComments
log (count paragraph of theRead)
set theList to {}
repeat with i from 1 to (count paragraph of theRead)
copy paragraph i of theRead to end of theList
end repeat
-- return theList
-- Get selected text
tell application "Script Editor"
set theDocument to front document
tell theDocument
set the selectedText to contents of selection
end tell
end tell
set theCommentsList to {}
if (selectedText = (get item 1 of theList)) then
copy item 2 of theList to end of theCommentsList
end if
(**
* set thePath to POSIX path of (path to desktop)
*
*)
This is file comments.txt
How is works…
In the bottom of the AS Script you find a comment select: POSIX path of (path to desktop)
run the script and it will output the second paragraph of comments.txt or item 2 of theList
I thought first to do csv but that need more work.
This version I find to work very well but of course if someone like to improve I will be happy.
Its use Pages with table of 2 column
| AppleScript commands | AppleScript comments
It will build a list of every cell, and search for a string that match the ones you select in
Script Editor. If its true it will copy item i + 1 of that cell to set the clipboard.
In other words the left column in table is AS commands and the right is AS comments.
Here is the code, the last handler could be deleted… the comments at beginning is only for test
to setup a table sheet in pages with some text. It work as before…
select text inside Script Editor and run the script… So it would make sense to make the
script to be menu script or service script or applet.
Ps. Pages need to be open with a document that has table with 2 column that you fill with text.
EDIT: The idea about this project is to make description of text or user comments to programming
language. Specially useful when I could automate the description of anything I find to be useful
for instance method, property, class or custom code
I could properly get the description text directly from the method itself like Shane show me
to do with Core Image Filters.
(** Test example.
* set thePath to POSIX path of (path to desktop)
* set theDialog to display dialog
*
*)
-- Get selected text
tell application "Script Editor"
set theDocument to front document
tell theDocument
set the selectedText to contents of selection
end tell
end tell
tell application "Pages"
set theTable to its first table of document 1
tell theTable
-- Get title of commands and comments.
-- my textTitleGroup()
set textCells to my getTextFromCellToList()
set theList to {}
repeat with i from 1 to (count items of textCells)
if (get item i of textCells = selectedText) then
log true
copy item (i + 1) of textCells to end of theList
end if
end repeat
-- Set the clipboard of returned text.
try
set the clipboard to (item 1 of theList) as text
end try
end tell
end tell
on getTextFromCellToList()
tell application "Pages"
set theTable to its first table of document 1
tell theTable
set theList to {}
repeat with i from 1 to 2
copy its value of cell to end of theList
end repeat
end tell
end tell
end getTextFromCellToList
on textTitleGroup()
tell application "Pages"
set theTable to its first table of document 1
tell theTable
tell range (the name of cell 1 of row 1) to set stringTitleC1 to its value of cell
tell range (the name of cell 2 of row 1) to set stringTitleC2 to its value of cell
return {stringTitleC1, stringTitleC2}
end tell
end tell
end textTitleGroup