Hav asked this question in a reply but...

Once i have saved something to the clipboasrd is it possible to convert it to a String.

I guess this is a string normally:

set hello to “This is a greeting”

Is there a way i can convert the clipboard to have the same structure, as this would help my problem, which is really bugging me.

Cheers

I’m not 100% sure what you are asking. Does this do what you want?

set the clipboard to AsText(the clipboard)

on AsText(str)
	--coerce Unicode or other text to styled string to plain text
	try
		return (((str as string) as record)'s «class ktxt»)
	end try
	return str -- if plain text to begin with
end AsText

erm, not to sure, as i get an error.

I ma going through photoshop and the error is:

I just cut and pasted and changed a small bit:

here it is:



--this converts the clipboard text to string
on AsText(str)
	--coerce Unicode or other text to styled string to plain text 
	try
		return (((str as string) as record)'s «class ktxt»)
	end try
	return str -- if plain text to begin with 
end AsText
-- end function


tell application "Adobe Photoshop 7.0"
	activate
	
	set fileName to name of current document
	set the clipboard to caption of info of current document <-- this is where is set the clipboard
	--runs the conversion function
	set documentCaption to AsText(the clipboard)  <-- this is where the error is spat out
	close current document
end tell


Do you see why?, what does <> do?? something about txt i guess but what pls?

Hmm. I don’t have access to PS but it’s possible that it has its own clipboard. It might also be tripping on the handler. Try this:

--this converts the clipboard text to string 
on AsText(str) 
   --coerce Unicode or other text to styled string to plain text  
   try 
      return (((str as string) as record)'s «class ktxt») 
   end try 
   return str -- if plain text to begin with  
end AsText 
-- end function 
 
 
tell application "Adobe Photoshop 7.0" 
   activate 
    
   set fileName to name of current document 
   set the clipboard to caption of info of current document <-- this is where is set the clipboard 
   --runs the conversion function 
   set documentCaption to my AsText(the clipboard)  <-- this is where the error is spat out 
   close current document 
end tell

I won’t claim to know exactly what «class ktxt» means (it’s not my script) but, in a nutshell, here’s how I understand it. The clipboard sometimes contains styled text. This means that besides the actual text, there is other information that describes the formatting. The «class ktxt» must extract only the raw text from the styled text record. All I know is that it works for me. :slight_smile:

– Rob

i get the following error:

This i guess is because it can t convert the clipboard into the string.

I know it does store to global clipboard as i normally just paste it into the right form field.

There must be a way , all i did was copy your code snippet.

argh!!! :x there must be

If you run this, what shows up in the result window?

tell application "Adobe Photoshop 7.0"
	activate  
	set foo to caption of info of current document <-- this is where is set the clipboard 
end tell 
class of foo

i have solved the problem at last.

And asa always with programming it is something that i cahnaged a couple of days ago that was actually really needed.

Hmmmm. This is the final code:::


--this converts the clipboard text to string 
on AsText(str)
	--coerce Unicode or other text to styled string to plain text  
	try
		return (((str as string) as record)'s «class ktxt»)
	end try
	return str -- if plain text to begin with  
end AsText
-- end function 


tell application "Adobe Photoshop 7.0"
	activate
	
	set fileName to name of current document
	set the clipboard to caption of info of current document as text
	--runs the conversion function 
	set documentCaption to my AsText(the clipboard)
	close current document
end tell

The bit that was wrong was that i didnt save the clipboard as text.

I reckon that this could have saved me about 3 days of twidling my thumbs. At least i got paidf for it!! :lol:

So maybe you don’t even need the conversion handler.

Is there a reason why you are using the clipboard instead of a variable? Here are a couple of alternates to try if you feel like messing with it.

 -- No clipboard and no text handler --
tell application "Adobe Photoshop 7.0" 
   activate 
   set fileName to name of current document 
   set caption_ to caption of info of current document as text 
   --runs the conversion function 
   set documentCaption to caption_ 
   close current document 
end tell 
 -- No clipboard with text handler --
tell application "Adobe Photoshop 7.0" 
   activate 
   set fileName to name of current document 
   set caption_ to caption of info of current document as text 
   --runs the conversion function 
   set documentCaption to my AsText(caption_) 
   close current document 
end tell 

--this converts the clipboard text to string 
on AsText(str) 
   --coerce Unicode or other text to styled string to plain text  
   try 
      return (((str as string) as record)'s «class ktxt») 
   end try 
   return str -- if plain text to begin with  
end AsText 
-- end function 

– Rob

argh!!!

what you say might be true and will have a look abit later. But i now have another problem.

It works great but only once.

If i try and do it again then there are problems. basically what i am doing, if you havent read my other posts, is to put them in with Internet Explorer.

This is th ewhole code


on AsText(str)
	--coerce Unicode or other text to styled string to plain text  
	try
		return (((str as string) as record)'s «class ktxt»)
	end try
	return str -- if plain text to begin with  
end AsText
-- end function 


tell application "Adobe Photoshop 7.0"
	activate
	
	set fileName to name of current document
	set the clipboard to caption of info of current document as text
	--runs the conversion function 
	set documentCaption to my AsText(the clipboard)
	close current document
end tell


tell application "Internet Explorer"
	Activate
	set imageNumber to 103828
	
	--this url will fill the form and save the informsatio of the file.  
	(************************************************
	* insert=image <= inserts the image											
	* libryno=filename <= insert the filename as library number						
	* physical=cd number <= this will insert the cd number of the CD, in caps	
	* caption=blank <= this should be blank, as it doesn't do anything		
	* description=documentcaption <= this will insert the caption in the right area
	* format=N <= this will set the fprmat to negative					
	* photogid=25 <= this will give the photographer, 25 is ad blake 	
	*************************************************)
	
	OpenURL "http://www.bl......s.com/admin/libadd.asp?action=insert&image=" & imageNumber & "&libraryno=" & fileName & "&physical=&caption=&description=" & documentCaption & "&format=O&photogid=29"
	
end tell

i really dont know why its not doing it more than once. IE throws up an error:

just when i thought tha ti solved it

Is it possible that you are enountering documents where the variables contain a space or some other character that is causing the URL to be invalid? You might need to use a routine to encode the URL before passing it to the browser.

This is why it’s helpful not to post the same question in different threads (see this topic).

Part of the problem may also be that you are trying to do things within the tell blocks for applications when they don’t need to be done there and, possibly, can’t be done there. Simply set your initial values in Photoshop then coerce them to strings (and encode them) outside of any tell block then try again with the URL and see if that works any better.

Jon

Aha! I haven’t followed that thread since I don’t know enough to offer anything useful. :stuck_out_tongue:

sorry for cross posting, thanks for all the help.

I have solved the problem and now it works perfectly, i have moved some stuff from inside the tell blocks as was suggested.



----------------------
--clear the variables
set documentCaption to ""
set fileName to ""
set imageNumber to ""
-----------------------
--this converts the clipboard text to string 
on AsText(str)
	--coerce Unicode or other text to styled string to plain text  
	try
		return (((str as string) as record)'s «class ktxt»)
	end try
	return str -- if plain text to begin with  
end AsText
-- end function 


tell application "Adobe Photoshop 7.0"
	activate
	--set the filename to that of the current document this way it can be used more tan once
	set fileName to name of current document
	--get the captiona nd send it to the clipboard as text
	set the clipboard to caption of info of current document as text
	close current document
end tell

--runs the conversion function 
set documentCaption to my AsText(the clipboard)

--set the clipboard so that the filename can be pasted into the txt document
set the clipboard to fileName as text

--set the image number to be used
set imageNumber to 103835

--open IE
tell application "Internet Explorer"
	Activate
		
	(************************************************
	* insert=image <= inserts the image											
	* libryno=filename <= insert the filename as library number						
	* physical=cd number <= this will insert the cd number of the CD, in caps	
	* caption=blank <= this should be blank, as it doesn't do anything		
	* description=documentcaption <= this will insert the caption in the right area
	* format=N <= this will set the fprmat to negative					
	* photogid=25 <= this will give the photographer, 25 is ad blake 	
	*************************************************)
	
	OpenURL "http://www.bl.....s.com/admin/libadd.asp?action=insert&image=" & imageNumber & "&libraryno=" & fileName & "&physical=&caption=&description=" & documentCaption & "&format=O&photogid=10"
	
end tell

Thanks, have left it quite long as i know it works, will fidlle and tidy when the application works “to all its glory” so tio speak.