• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: String manipulation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String manipulation


  • Subject: Re: String manipulation
  • From: Thomas Fischer <email@hidden>
  • Date: Fri, 07 Jun 2013 01:29:52 +0200

Hi Rudolf,

this seems overly complicated,
If you use the Satimage Osax anyway you might try to accomplish the same result using regular expressions:

tell application "Finder"
	set myFile to the selection as alias
	set oldName to the name of myFile
	tell me to set newName to change "(\\d+)\\.(\\d+)\\.(\\d+)" into "\\3.0\\2.0\\1" in oldName with regexp
	tell me to set newName to change "\\d*(\\d\\d)\\.\\d?(\\d\\d)\\.\\d?(\\d\\d)" into "\\1.\\2.\\3" in newName with regexp
	log oldName
	set the name of myFile to newName
end tell

Depending of the names you have to deal with this might work.

Best
Thomas


Am 06.06.2013 um 23:36 schrieb Iurista GmbH:

> I have Filenames in form of "some_text xx.xx.xx some_text", where xx.xx.xx is a date (german syntax: ie. 01.06.13 for the first of June)
> I try to convert the "date part"  into the form YYMMdd (ie. 130601).
>
> The tricky thing is to get the part "xx.xx.xx", which I highlight in Finder, to be copied.
>
> I managed to to this (in OSX 10.6.8)
>
> tell application "Finder"
> 	delay 1 --Why this one ???
>
> 	tell application "System Events"
> 		tell process "Finder"
> 			keystroke "c" using command down
> 		end tell
> 	end tell
>
> 	set oldDate to the clipboard as text
>
> 	tell application "System Events"
> 		tell process "Finder"
> 			key code 76
> 		end tell
> 	end tell
>
> 	activate
> 	set SEL to selection
> 	set aSel to selection as alias
> 	set NSel to name of item 1 of SEL as string
>
>
> 	set oldDelim to AppleScript's text item delimiters
> 	set AppleScript's text item delimiters to "."
> 	set P1 to text item 1 of oldDate
> 	set P2 to text item 2 of oldDate
> 	set P3 to text item 3 of oldDate
> 	set AppleScript's text item delimiters to oldDelim
>
> 	if number of characters of P1 < 2 then set P1 to ("0" & P1) as text
> 	if number of characters of P2 < 2 then set P2 to ("0" & P2) as text
> 	set newDate to (P3 & P2 & P1) as string
>
> 	set x to (change oldDate as string into newDate in NSel) --Satimage Osax
> 	set name of aSel to x
>
> end tell
>
> and I trigger that script via Quickeys
>
> It works so far, but what I'm wondering is the delay in the second line. It does not function without it, but I have any idea why.
> Somebody has a guess?
> Rudolf
>
>
>
>
> --
> The price of freedom is eternal vigilance (Thomas Jefferson, US President)
>
> This mail is from:
> Rudolf O. Durrer
> IURISTA CONSULT GmbH
> Legal Counselors
> Switzerland
>
> email@hidden
> email@hidden
>
>
>
>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: String manipulation
      • From: Iurista GmbH <email@hidden>
References: 
 >String manipulation (From: Iurista GmbH <email@hidden>)

  • Prev by Date: Re: String manipulation
  • Next by Date: Re: String manipulation
  • Previous by thread: Re: String manipulation
  • Next by thread: Re: String manipulation
  • Index(es):
    • Date
    • Thread