Calling ExifTool from AppleScript

Started by rajkhand, October 02, 2019, 08:37:16 AM

Previous topic - Next topic

rajkhand

I am getting Error
error "Error creating directory 2019-07-13
Warning: Error creating directory for '2019-07-13/DSC08293.jpg' - /Volumes/HackSSD/Testing Space/DSC08293.jpg" number 1


when I run the following code of AppleScript in ScriptEditor Mojave 10.14.6 ExifTool ver 11.65
set folder_name to quoted form of "/Volumes/HackSSD/Testing Space"
do shell script "cd " & folder_name
set ExifTool to "/usr/local/bin/exiftool  '-directory<CreateDate'  -d %Y-%m-%d "
do shell script ExifTool & space & folder_name

I have tried removing & space with the same error
If I run the below code in terminal it works perfectly
exiftool '-Directory<CreateDate' -d %Y-%m-%d /Volumes/HackSSD/Testing\ Space

What I am doing wrong?

Hayo Baan

The problem is that you changed directory in a separate do shell script, this doesn't work; after returning from this, the current directory is what it was before. So when you later run the exiftool command, you're not in the right directory.

Try this instead:
set folder_name to quoted form of "/Volumes/HackSSD/Testing Space"
set ExifTool to "/usr/local/bin/exiftool  '-directory<CreateDate'  -d %Y-%m-%d "
do shell script "cd " & folder_name & "; " & ExifTool & folder_name
Hayo Baan – Photography
Web: www.hayobaan.nl

rajkhand

It Works! Thanks!
Can you please explain what the last line does
why it is necessary to cd to the directory?
As exiftool should execute properly when the path of the directory is given.
In terminal as stated earlier it works irrespective of the current directory.

Phil Harvey

The command will execute and run from anywhere, but the way you have done things the output directories (based on CreateDate) are created in the current working directory.  Something like this should also work:

set folder_name to quoted form of "/Volumes/HackSSD/Testing Space"
set ExifTool to "/usr/local/bin/exiftool  '-directory<CreateDate'  -d " & folder_name & "/%Y-%m-%d "
do shell script ExifTool & space & folder_name


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

rajkhand

first sorry for not giving the main purpose of this code.

The main reason is to write a folder action script for a folder where when I copy images from my SD card to this folder should be moved to a directory like yyyy-mm-dd based on the picture taken date. The directory if not present should be created. Based on your earlier reply the code is like

on adding folder items to this_folder after receiving added_items
    try

        repeat with theCurrent_item in added_items
            set filePosixPath to quoted form of (POSIX path of (theCurrent_item as alias))
            set fileType to (do shell script "file -b " & filePosixPath) --Test if it is a directory
            if fileType = "directory" then
                return
            end if

        end repeat


        set folder_name to quoted form of (POSIX path of (this_folder as alias))

        set ExifTool to "/usr/local/bin/exiftool  '-directory<CreateDate'  -d %Y-%m-%d "
        do shell script "cd " & folder_name & "; " & ExifTool & folder_name

    end try
end adding folder items to


Is there any scope of improvement? will it work without "cd" to the attached directory?
Thanks.

Hayo Baan

Looks fine to me (but I'm not an Apple Script expert).

Instead of using the cd command, you can make use of Phil's suggestion:
set ExifTool to "/usr/local/bin/exiftool  '-directory<CreateDate'  -d " & folder_name & "/%Y-%m-%d "
do shell script & ExifTool & folder_name
Hayo Baan – Photography
Web: www.hayobaan.nl