Should I be able to do this with Applescript?

Have your say on issues related to using a DSLR camera.

Moderator: Moderators

Forum rules
Please ensure that you have a meaningful location included in your profile. Please refer to the FAQ for details of what "meaningful" is.

Should I be able to do this with Applescript?

Postby ATJ on Wed Dec 22, 2010 5:52 pm

As part of my conversion from Windows to Mac, I have some export actions in LR2/Mogrify that I need to convert.

Basically, I have some batch files that call ExifTool to extract Exif data to a file.

\Export Actions\dive exiftool.bat
Code: Select all
for %%A in (%*) do call "C:\atj.com.au\atj.net.au\exiftool" %%A
exit


c:\atj.com.au\atj.net.au\exiftool.bat
Code: Select all
del "%~dp1\exif\%~n1.exif"
c:\programs\exiftool-7.06\exiftool.exe -d "%%d/%%m/%%Y %%H:%%M:%%S" -@ "C:\atj.com.au\exiftool.arg" -w %%d\exif\%%f.exif "%~dpn1.jpg"


Should I be able to do the above (fairly easily) with Applescript? Is there a better way?
User avatar
ATJ
Senior Member
 
Posts: 3982
Joined: Fri Feb 18, 2005 10:44 am
Location: Blue Mountains, NSW

Re: Should I be able to do this with Applescript?

Postby photohiker on Thu Dec 23, 2010 12:01 am

You might be able to do something similar with Applescript, but I suspect it might be easier with shell scripting. Mac OS X is based on unix, and it has a powerful shell language built in.

http://developer.apple.com/internet/ope ... pting.html

My system has exiftool installed in /usr/bin/exiftool I'm not exactly sure what your .bats are doing, but this should get you started:

Code: Select all
michael$ ls -l test.sh
-rwxr-xr-x  1 michael  michael  63 22 Dec 23:11 test.sh

michael$ cat test.sh
#!/bin/bash
for i in *.jpg
do
/usr/bin/exiftool "$i"
done

michael$ ./test.sh

ExifTool Version Number         : 7.23
File Name                       : 4915_071218.jpg
Directory                       : .
File Size                       : 406 kB
File Modification Date/Time     : 2007:12:19 15:06:41
File Type                       : JPEG
MIME Type                       : image/jpeg
Exif Byte Order                 : Little-endian (Intel, II)
[..] etc (output like this for each .jpg in the directory)



There may already be other solutions to you problem though...

HTH

Michael
photohiker
Senior Member
 
Posts: 687
Joined: Sun Mar 02, 2008 11:56 am
Location: Burnside, South Australia.

Re: Should I be able to do this with Applescript?

Postby ATJ on Thu Dec 23, 2010 8:20 am

Thanks. I had thought of shell scripts but I couldn't find any information on processing parameters, especially the manipulation of paths and filenames.

I believe the first bat job can be converted easily, so:
Code: Select all
for %%A in (%*) do call "C:\atj.com.au\atj.net.au\exiftool" %%A
exit


would become:
Code: Select all
for i in $*
do
/Users/andrewtj/atj.com/atj.net.au/diveexiftool.sh "$i"
done


Lightroom calls the export action once for each export, but if the export included multiple files, it will pass each filename as parameters to the action. So this first batch file/script has to convert from one invocation with multiple filenames to one call of the second batch file/script for each filename.

It is the second one that I'm getting stuck with... what it does is as follows... (and I pasted the wrong version above)
Code: Select all
del "%~dp1\DiveEXIF\%~n1.exif"
c:\programs\exiftool-7.06\exiftool.exe -d "%%d/%%m/%%Y %%H:%%M:%%S" -@ "C:\atj.com.au\atj.net.au\exiftool.arg" -w %%d\DiveEXIF\%%f.exif "%~dpn1.jpg"


1. Delete the file with the same filename but an extension of .exif from the subdirectory DiveEXIF which is in the same directory as the file to be processed
2. Run exiftool against the file to be processed and put the output in a file with the same filename but with an extension of .exif and place it in the subdirectory DiveEXIF.

Now, I am able to do the second step but not the first. The first step is necessary because exiftool won't overwrite existing files.

Here's the second step:
Code: Select all
exiftool -d "%d/%m/%Y %H:%M:%S" -@ "/Users/andrewtj/atj.com/atj.net.au/exiftool.arg" -w %d/DiveEXIF/%f.exif "$1"


How would I do the first step? How do I extract just the path and just the filename without the extension from the passed full path and filename?

By the way, the above shell scripts work fine with Lightroom, but I have to manually delete the .exif file if it exists already.
User avatar
ATJ
Senior Member
 
Posts: 3982
Joined: Fri Feb 18, 2005 10:44 am
Location: Blue Mountains, NSW

Re: Should I be able to do this with Applescript?

Postby photohiker on Thu Dec 23, 2010 10:39 am

Hi ATJ,

Got to fly, but a couple of hints:

rm is the unix equivalent of del

Have a look here for info on manipulating the filename:

http://www.unix.com/shell-programming-s ... -name.html

google can help a lot with unix shell programming, there is lots of info out there.

Michael
photohiker
Senior Member
 
Posts: 687
Joined: Sun Mar 02, 2008 11:56 am
Location: Burnside, South Australia.

Re: Should I be able to do this with Applescript?

Postby ATJ on Thu Dec 23, 2010 11:19 am

Yes, I know about rm - that isn't the problem.

I have also been Googling for the last 4 or 5 hours.

I am nearly there...

if I do
F=$1 ($1 is the full path and filename of the jpg file)

${F%.*} gives me the full path and filename without the extension
${F%/*} gives me just the path (which is one of the things I need)
${F##*/} gives me the filename without the path, but with the extension

I just have to work out how to get the filename without the path and without the extension... oh... maybe I have it by combining them.
User avatar
ATJ
Senior Member
 
Posts: 3982
Joined: Fri Feb 18, 2005 10:44 am
Location: Blue Mountains, NSW

Re: Should I be able to do this with Applescript?

Postby ATJ on Thu Dec 23, 2010 11:37 am

OK.. I have got it working now... this is the new shell script:
Code: Select all
F=$1
G=${F##*/}
rm ${F%/*}/DiveEXIF/${G%.*}.exif
exiftool -d "%d/%m/%Y %H:%M:%S" -@ "/Users/andrewtj/atj.com/atj.net.au/exiftool.arg" -w %d/DiveEXIF/%f.exif "$1"


I was only able to do it by Googling and finding examples of something similar and then with a bit of trial and error I got it working. There doesn't seem the be any documentation on the use of ${} - at least not that I could find.
User avatar
ATJ
Senior Member
 
Posts: 3982
Joined: Fri Feb 18, 2005 10:44 am
Location: Blue Mountains, NSW

Re: Should I be able to do this with Applescript?

Postby photohiker on Thu Dec 23, 2010 1:37 pm

ATJ wrote:OK.. I have got it working now... this is the new shell script:
[..]
I was only able to do it by Googling and finding examples of something similar and then with a bit of trial and error I got it working.


There you go. :)

Finding help with some of these things when you are new to them is quite recursive and you have to know what you are looking for to be able to search effectively for it. Has been known to numb the mind...

ATJ wrote:There doesn't seem the be any documentation on the use of ${} - at least not that I could find.


Here it is:

http://www.gnu.org/software/bash/manual ... -Expansion

You have a local copy of this, try typing man bash in the terminal and search for Brace Expansion

Merry Christmas to all.

Michael
photohiker
Senior Member
 
Posts: 687
Joined: Sun Mar 02, 2008 11:56 am
Location: Burnside, South Australia.

Re: Should I be able to do this with Applescript?

Postby ATJ on Thu Dec 23, 2010 1:46 pm

photohiker wrote:Here it is:

http://www.gnu.org/software/bash/manual ... -Expansion

You have a local copy of this, try typing man bash in the terminal and search for Brace Expansion

Actually, from reading that reference, it is not Brace Expansion as it says:
To avoid conflicts with parameter expansion, the string ‘${’ is not considered eligible for brace expansion.


However, that was able to point me to Shell Parameter Expansion which is what I'm doing.

Thanks, that is helpful.
User avatar
ATJ
Senior Member
 
Posts: 3982
Joined: Fri Feb 18, 2005 10:44 am
Location: Blue Mountains, NSW

Re: Should I be able to do this with Applescript?

Postby photohiker on Thu Dec 23, 2010 2:14 pm

Oh. Yes, so it is. Sorry about that.

You seem to be getting along with the shell just fine. :up:

Something I do in my scripts is to tune them with useful error trapping and messages as warts reveal themselves. For instance, what happens if a non jpeg file finds its way into the directory, or an unreadable file turns up due to permissions or corruption. etc.

Michael
photohiker
Senior Member
 
Posts: 687
Joined: Sun Mar 02, 2008 11:56 am
Location: Burnside, South Australia.

Re: Should I be able to do this with Applescript?

Postby ATJ on Sun May 15, 2011 3:58 pm

Bloody Adobe...

I've had the shell script working fine for a few months. It automatically gets called when I export dive photos. I upgraded to LR3.4 a couple of weeks ago and tried to export my dive photos from Friday night - first set of dive photos I'd done since upgrading. Well, it no longer works. There's nothing wrong with the script... it's the location. The wonderful programmers at Adobe seem to have screwed up and also didn't do their regression testing.

Lightroom expects the shell scripts to be in $HOME/Library/Application Support/Adobe/Lightroom/Export Actions (and that's the only place you can select them from). It appears it can't cope with the spaces and you end up getting an error in the System console when it tries to execute:
Code: Select all
15/05/11 1:33:04 PM   [0x0-0xec0ec].com.adobe.Lightroom3[4032]   sh: /Users/andrewtj/Library/Application\ Support/Adobe/Lightroom/Export\ Actions/diveexiftool2.sh: No such file or directory


If I copy the script to the desktop (or any other path without spaces, I assume), use "Open in Other Application" and point to script on the Desktop it all works fine.

*SIGH*
User avatar
ATJ
Senior Member
 
Posts: 3982
Joined: Fri Feb 18, 2005 10:44 am
Location: Blue Mountains, NSW

Re: Should I be able to do this with Applescript?

Postby photohiker on Sun May 15, 2011 7:32 pm

I think you mean "Bloody Adobe" ? :|

From what you are saying, the only change has been LR -> 3.4?

Hope you get it sorted.

Michael
photohiker
Senior Member
 
Posts: 687
Joined: Sun Mar 02, 2008 11:56 am
Location: Burnside, South Australia.

Re: Should I be able to do this with Applescript?

Postby ATJ on Sun May 15, 2011 10:13 pm

photohiker wrote:From what you are saying, the only change has been LR -> 3.4?

LR 2.7 -> 3.4. Means I missed 3.0, 3.1, 3.2 and 3.3.

I didn't really need to upgrade to LR3 until I got my D7000. There's no support for the D7000 in LR2 so I have to go to LR3 and live with all the new bugs - I've found 3 already.

It really pisses me off that companies these days make you to pay for "upgrades" to their software when they don't bother doing regression testing and expect the paying customers to find the bugs for them.
User avatar
ATJ
Senior Member
 
Posts: 3982
Joined: Fri Feb 18, 2005 10:44 am
Location: Blue Mountains, NSW


Return to General Discussion

cron