Removing Leading Text

Hi!

I just need a little bit of help removing some leading text of a string of text that is copied. Here’s my script:

tell application "System Events" to tell process "XXX"
	tell (1st window whose value of attribute "AXMain" is true)
		set windowTitle to value of attribute "AXTitle"
	end tell
	try
		set cxName to value of static text 2 of splitter group 1 of splitter group 1 of window 1
           on error number -1719
		set cxName to "Unable to find Name"
	end try
	set the clipboard to (cxName)

end tell

set txt to the clipboard as text
set txt_capped to titlecase(txt)
on titlecase(txt)
	return do shell script "python -c \"import sys; print unicode(sys.argv[1], 'utf8').title().encode('utf8').strip()\" " & quoted form of txt
end titlecase

This pastes out a result of “Customer - FirstName” and I would like to remove the "Customer - " part to just be left with the first name. Appreciate any help and happy to help clarify if not explained properly.

You may try :

tell application "System Events" to tell process "XXX"
	tell (1st window whose value of attribute "AXMain" is true)
		set windowTitle to value of attribute "AXTitle"
	end tell
	try
		set cxName to value of static text 2 of splitter group 1 of splitter group 1 of window 1
	on error number -1719
		set cxName to "Unable to find Name"
	end try
	set the clipboard to (cxName)
	
end tell

set txt to the clipboard as text
set txt to my supprime(txt, "Customer - ") -- was  wrongly t when it was supposed to be txt !!!!!!
set txt_capped to titlecase (txt)
on titlecase (txt)
	return do shell script "python -c \"import sys; print unicode(sys.argv[1], 'utf8').title().encode('utf8').strip()\" " & quoted form of txt
end titlecase



#=====
(*
removes every occurences of d in text t
*)
on supprime(t, d)
	local oTIDs, l
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set l to text items of t
	set AppleScript's text item delimiters to ""
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end supprime

#=====

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 11 juillet 2018 19:23:17

Thanks.

I tried this:

tell application "System Events" to tell process "XXX"
   tell (1st window whose value of attribute "AXMain" is true)
       set windowTitle to value of attribute "AXTitle"
   end tell
   try
       set cxName to value of static text 2 of splitter group 1 of splitter group 1 of window 1
   on error number -1719
       set cxName to "Unable to find Name"
   end try
   set the clipboard to (cxName)
   
end tell

set txt to the clipboard as text
set txt to my supprime(t, "Customer - ")
set txt_capped to titlecase (txt)
on titlecase (txt)
   return do shell script "python -c \"import sys; print unicode(sys.argv[1], 'utf8').title().encode('utf8').strip()\" " & quoted form of txt
end titlecase

on supprime(t, d)
   local oTIDs, l
   set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
   set l to text items of t
   set AppleScript's text item delimiters to ""
   set t to l as text
   set AppleScript's text item delimiters to oTIDs
   return t
end supprime

And receive “The variable t is not defined.”

I’m pretty new but happy to learn and improve.

Oops ! I left a typo corrected above.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 11 juillet 2018 20:39:24

This worked! Thank you so much!