Thursday, September 20, 2018

#1 2018-07-11 10:56:33 am

Surge87
Member
Registered: 2018-07-11
Posts: 5

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:

Applescript:

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.

Offline

 

#2 2018-07-11 11:23:59 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3256

Re: Removing Leading Text

You may try :

Applescript:

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

Last edited by Yvan Koenig (2018-07-11 12:40:38 pm)

Offline

 

#3 2018-07-11 12:23:52 pm

Surge87
Member
Registered: 2018-07-11
Posts: 5

Re: Removing Leading Text

Thanks.

I tried this:

Applescript:

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.

Offline

 

#4 2018-07-11 12:39:29 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3256

Re: Removing Leading Text

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

Offline

 

#5 2018-07-11 01:58:10 pm

Surge87
Member
Registered: 2018-07-11
Posts: 5

Re: Removing Leading Text

Yvan Koenig wrote:

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!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)