Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi All,
Using apple script selected text is copied to the clipboard.Now i need to write the content to the text file from the clipboard and save as text file it on desktop or in some other path.How to go about it?
tell application "MathMagic Pro 6.04 InD"
activate
tell application "System Events"
tell process "MathMagic Pro InD"
click menu item "Select All" of menu "Edit" of menu bar 1
click menu item "Copy" of menu "Edit" of menu bar 1
end tell
end tell
end tell
Here is the code which copies the content to the clipboard.
Imported from the Apple Support Forums via the Wayback Machine 🔗
Use the following command:
do shell script ("echo " & (the clipboard) & " >> ~/Desktop/test.txt")
If the file already exists, the text will be appended to it.
(48544)
0
hungryjoe·
Imported from the Apple Support Forums via the Wayback Machine 🔗
You can get the contents of the clipboard very easily.
set myText to the clipboard
Writing to a file is also not that difficult.
-- Create a file handler for the file to write to. set myFile to (open for access alias "path:to:file" with write access) try -- Delete current contents of the file set eof myFile to 0 -- Write to file write myText to myFile end try -- Close the file close access myFile
0
sakthi_perumal·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi Niel,
I just ran the script, but i am getting apple script error which says "Can’t make {«class MMFM»:«data MMFM5C494E464F524D4154494.... }into type Unicode text".
I also do not want to appned the text to the existing text file.I need to delete and create a new file with same name and write the content to it
Thanks
Sakthi
0
sakthi_perumal·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi,
I tried your script.
The set myFile to (open for access alias "path:to:file" with write access) gives an error while compiling it. so i changed the "write access" to "write permission".
open for access alias "path:to:file" with write access expects a file to be already present.But i need to create a file if not present
So I created a file "Test.txt" in the desktop. Now i ran the script.But i see some values which is not in readable format.
Is there some thing to do with clipboard format?
Here is the script
set myText to the clipboard
-- Create a file handler for the file to write to.
set file_Path to (path to current user folder as string) & "Desktop:Text.txt"
set myFile to (open for access alias file_Path with write access)
try
-- Delete current contents of the file
set eof myFile to 0
-- Write to file
write myText to myFile
end try
Thanks
Sakthi
0
hungryjoe·
Imported from the Apple Support Forums via the Wayback Machine 🔗
open for access alias "path:to:file" with write access expects a file to be already present.But i need to create a file if not present
This can be corrected by using a file instead of an alias.
open for access posix file "~/Desktop/Test.txt"
Now i ran the script.But i see some values which is not in readable format.
Is there some thing to do with clipboard format?
Looking at your reply to Niel I would say that this is happening because your code for copying is placing the copied material on the clipboard not as text as an object of class «class MMFM», which is perhaps a format for MathMagic. If MathMagic supports applescript then maybe you can look its dictionary/documentation and see if it supports something like this:
set selectedText to selection as text set the clipboard to selectedText
I suspect the first command above might work even if the application doesn't support AppleScript but cannot really confirm it.
Cheers.
0
twtwtw·
Imported from the Apple Support Forums via the Wayback Machine 🔗
I downloaded MathMagic to take a look at it, and it's not scriptable. however, it should be easy enough to GUI script it so that it exports an image or laTex file that you can use elsewhere. you won't be able to save it as simple text, of course, because equations can't be properly rendered in text. what's you're bigger goal here?