String manipulation
String manipulation
- Subject: String manipulation
- From: Iurista GmbH <email@hidden>
- Date: Thu, 06 Jun 2013 23:36:18 +0200
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