Hey all,
I have list of records {fileA:nameFile, URLa:URL, fileB:nameFile, URLb:URL}
and I want to convert it into a document in textEdit such as:
NameFileA
NameFileB
And each name (which is only one for each line) is an hyperlink containing the corresponding URL.
I wrote the script below. It works.
My questions are:
Is there any better way to do it? I guess I am forced to use TextEdit, which is very little scriptable !!!
It is even impossible to say: “select word 2 of line 3 of paragraph 4”
To select some text I had to use command such: “key code 125 using {command down}” !!!
On the very top of the script I use the line:
"set target_app to (path to frontmost application as Unicode text)"
Which I copied from an example I found. Without this, it doesn’t work.
But I don’t really understand its function …
Here is the script:
set target_app to (path to frontmost application as Unicode text)
-- Making a list of records a sit will be in th final script
set theList1 to {}
set g_theFileName to "s41588x"
set thePath1_URL to "file:///Users/ldicroce/Desktop/Test%20Folder/s41588x.pdf"
set this_file_name to "s41588x"
set thePath2_URL to "file:///Users/ldicroce/Desktop/Test%20Folder/s41588x.pdf"
set end of theList1 to {filename1:g_theFileName, pathURL1:thePath1_URL, filename2:this_file_name, pathURL2:thePath2_URL}
# one more record
set g_theFileName to "s41588x"
set thePath1_URL to "file:///Users/ldicroce/Desktop/Test%20Folder/s41588x.pdf"
set this_file_name to "s41588x2"
set thePath2_URL to "file:///Users/ldicroce/Desktop/Test%20Folder/s41588x2.pdf"
set end of theList1 to {filename1:g_theFileName, pathURL1:thePath1_URL, filename2:this_file_name, pathURL2:thePath2_URL}
ParsingNameAndURL(theList1)
on ParsingNameAndURL(theList)
tell application "TextEdit"
activate
make new document
delay 0.5
repeat with i in theList
make new paragraph at end of paragraphs of text of document 1 with data ((filename1 of i) as string) & return
set the clipboard to ((pathURL1 of i) as string)
tell application "System Events"
-- keystroke (ASCII character 127) using {command down} -- key code 126 using {command down}
tell process (my target_app)
key code 125 using {command down} -- all the way down
delay 0.8
key code 126 using {option down, shift down} -- 1 paragraph up and selecting it
keystroke "k" using {command down}
delay 0.5
keystroke "v" using {command down}
keystroke return
end tell
end tell
make new paragraph at end of paragraphs of text of document 1 with data ((filename2 of i) as string) & return
set the clipboard to ((pathURL2 of i) as string)
tell application "System Events"
-- keystroke (ASCII character 127) using {command down} -- key code 126 using {command down}
tell process (my target_app)
key code 125 using {command down} -- all the way down
delay 0.8
key code 126 using {option down, shift down} -- 1 paragraph up and selecting it
keystroke "k" using {command down}
delay 0.5
keystroke "v" using {command down}
keystroke return
end tell
end tell
end repeat
end tell
end ParsingNameAndURL
Thanks !