On Jun 6, 2013, at 4:36 PM, Iurista GmbH wrote: 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 would get rid of the GUI scripting, if that's possible. Here is what I quickly tried …
property filename : "some_text 1.6.13 some_text"
set AppleScript's text item delimiters to {space} set dateWord to 0 set fileNameWords to (text items of filename) as list repeat with i from 1 to (count items of fileNameWords) if item i of fileNameWords contains "." then set oldDate to (item i of fileNameWords) as text set dateWord to i exit repeat end if end repeat
if dateWord = 0 then return -- error dialog needed here
set AppleScript's text item delimiters to {"."} set newDay to text item 1 of oldDate set newMonth to text item 2 of oldDate set newYear to text item 3 of oldDate
if length of newDay < 2 then set newDay to ("0" & newDay) if length of newMonth < 2 then set newMonth to ("0" & newMonth)
set newDate to (newYear & newMonth & newDay)
set item dateWord of fileNameWords to newDate set AppleScript's text item delimiters to {space} set newFileName to fileNameWords as text
display dialog filename & return & return & newFileName
It works, but I am not aware of details of your situation which may pose a problem.
You can select the file (not just part of the file name) and let your script find the date part. But ... Is the date part of your file always delimited by spaces? If not, then the script above will not be able to identify the date part. And, do your file names have an extension? If they do, you will first have to get the file name without the extension.
Hope this helps, however.
|