Hi,
I need to write clipboard contents (text) to a textfile (.txt format) at the path parent to the applescript application.
Can anyone please help me !
Thanks
-Kannan
Hi,
I need to write clipboard contents (text) to a textfile (.txt format) at the path parent to the applescript application.
Can anyone please help me !
Thanks
-Kannan
Does this do what you want (when saved as application)?
try
set cb_ to the clipboard
if class of cb_ is string then
tell application "Finder" to set myParent to (container of (path to me)) as text
try
set f to open for access file (myParent & "clipboard.txt") with write permission
set eof f to 0
write cb_ to f starting at eof
close access f
on error
try
close access f
end try
end try
end if
on error err_
display dialog err_
end try
– Rob
You are absolutely great Rob !
This is the script I needed. Thank you very much for your timely help.
But I the text file ‘clipboard.txt’ is created in the same folder applescript application.
My requirement is, I need to create the textfile ‘clipboard.txt’ one folder above (i.e., parent folder for applescript application).
Can you please tell me how this possible?
Thanks!
Kannan
This is the part that confused me. When you say ‘applescript application’, do you mean Script Editor?
– Rob
Sorry for the confusion.
Let me explain with example:
I have folder folder name ‘kannan’ which has the path ‘Macintosh HD:kannan’
My applescript application ‘clip’ developed using your code is under the folder ‘kannan’
Here comes my question:
Presently the ‘clipboard.txt’ is created under ‘Macintosh HD:kannan’
But I need to place/create the textfile ‘clipboard.txt’ under the path ‘Macintosh HD:’.
Is it clear now Rob?
Sorry if I not clear enough.
Some more questions:
When I creating the textfile ‘clipboard.txt’ TextEdit application is getting opened. Is there is anyway we can quit/close the TextEdit once the contents write to the textfile?
Will this work for all the platforms of Mac?
Thanks
-Kannan
Hi rob,
I got the answer from another post for detecting the parent folder
http://bbs.applescript.net/viewtopic.php?t=4462&highlight=parent
But I need to close the TextEdit once the textfield is created.
Thanks for your help once again!
-Kannan
Sorry not mentioning aout the change I have made to your script.
The change is:
tell application “Finder” to set myParent to folder of (container of (path to me)) as text
I have included folder of .
Is it right?
[/b]
I think I understand. Let’s see.
try
set cb_ to the clipboard
if class of cb_ is string then
tell application "Finder" to set myParent to (container of container of (path to me)) as text
try
set f to open for access file (myParent & "clipboard.txt") with write permission
set eof f to 0
write cb_ to f starting at eof
close access f
on error
try
close access f
end try
end try
end if
on error err_
display dialog err_
end try
TextEdit/the script isn’t opening the file automatically is it? If it opens when the file is double-clicked, it must be because TextEdit is the default application for .txt files. This script above should work on most recent versions of Mac OS. The application on each Mac which is designated to open .txt files should be able to open the file with no problem.
– Rob
Hi Rob,
the Container of is also working
Thanks
-Kannan