Apple Script question, change variable

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Apple Script question, change variable Thu Sep 12, 2013 6:29 pm • by Graf_Wetter
Hi,

I use this script to extract metadata from pdf files

Code: Select all
set posixPath to quoted form of (POSIX path of theFile) as string

set Aufl to (do shell script "exiftool -JoberstellungAuflage " & posixPath & " | awk  -F ' ' '{print$6}'")

return {hazelExportTokens:{Auflage:Aufl}}

The values of "Aufl" are numbers, e.g. "1.000"
Now I need to eliminate the "."
"1.000" should be changed to "1000" before it is written to the custom token.
So in general I need a search&replace for "." within the variable "Aufl" done with Apple Script or "do shell script".
Can anyone help ?
Thanks
Graf_Wetter
 
Posts: 37
Joined: Thu Aug 25, 2011 7:18 am

Re: Apple Script question, change variable Sun Sep 15, 2013 6:04 am • by Skeo
I'm rubbish with applescript, but I would use sed to remove a decimal in a shell script.

Code: Select all
sed 's/\.//'

note that the backslash quotes the period so that it isn't confused for a regex.

this syntax finds the first period in the standard input and substitutes it with nothing (i.e. deletes it).
If you want to get rid of all the periods, add "g" to the end.

to feed a variable to the standard input you could pipe it from echo with something like this

Code: Select all
VAR="some code or value"
VAR=$(echo $VAR | sed 's/\.//g')

so if VAR was "1.000", it would then be changed to "1000"
because I added the g at the end of this one. "1.000.000" would change to "1000000". Without the g it would go to "1000.000".
Skeo
 
Posts: 31
Joined: Mon Jan 02, 2012 7:53 pm

Thanks Skeo for your solution.
Works great.
This is my code:
Code: Select all
set posixPath to quoted form of (POSIX path of theFile) as string
set Aufl to (do shell script "exiftool -JoberstellungAuflage " & posixPath & " | awk  -F ' ' '{print$6}'")
set Aufl to (do shell script "echo " & Aufl & " | sed 's/\\.//g'")

Solved.

Graf Wetter
Graf_Wetter
 
Posts: 37
Joined: Thu Aug 25, 2011 7:18 am


Return to Support