1 2 Previous Next 16 Replies Latest reply on Jan 14, 2016 3:33 PM by MacCarl

    Applescript performs differently from within Filemaker

    jarvphot

      Hello, thanks in advance for any help.

       

      I have an Applescript that opens Photoshop and converts an image to a jpeg proof. The script adds the job name and the filename to the face of the photograph so it's easier for clients to tell me which image they want as their final selection.

       

      When I run the script from Script Editor it performs correctly, adding this text to the face of the image:

      Smith_John 02

       

      However, when I run the same Applescript from within a Filemaker script, I get this instead:

      Smith_John 0<<2

       

      This only happens if the applescript is called by the Filemaker script using the Run Applescript command.

       

      Here is a simplified version of the applescript:

       

      --GET DATA FROM FILEMAKER

      tell application "FileMaker Pro Advanced"

        set jobFolder to cell "Paths::Path to Job folder" of current record

        set jobType to cell "Jobs::JobType" of current record

        set jobDescription to cell "Jobs::JobDescription" of current record

      end tell

       

       

      --SET OUTPUT PATH

      set targetFolder to path to desktop

       

       

      --SELECT IMAGES FOR PROCESSING

      choose file of type "public.image" with prompt ¬

        "Select Images" with multiple selections allowed

       

      set fileList to result

       

      --CONVERT IMAGES

      with timeout of 60 * 60 * 24 seconds

        tell application "Adobe Photoshop CC 2015"

        set ruler units of settings to pixel units

        repeat with aFile in fileList

        open aFile showing dialogs never

        set background color to {class:RGB color, red:255, green:255, blue:255}

       

        tell the current document

       

        set fName to name

        set baseName to fName

        repeat with idx from 1 to (length of fName)

        if (item idx of fName = ".") then

        set baseName to (items 1 thru (idx - 1) of fName) as string

        exit repeat

        end if

        end repeat

       

        flatten

       

        if height > width then

        resize image height 1500

        else

        resize image width 1500

        end if

       

        set docHeight to height

        set docWidth to width

       

        make new art layer with properties {kind:normal, opacity:30}

        select region {{0, (docHeight - 60)}, {docWidth, (docHeight - 60)}, {docWidth, (docHeight - 170)}, {0, (docHeight - 170)}} without antialiasing

        fill selection with contents {class:RGB hex color, hex value:"000000"}

        deselect

       

        make new art layer with properties {kind:normal, opacity:30}

        select region {{0, (docHeight - 5)}, {docWidth, (docHeight - 5)}, {docWidth, (docHeight - 52)}, {0, (docHeight - 52)}} without antialiasing

        fill selection with contents {class:RGB hex color, hex value:"000000"}

        deselect

       

        make new art layer with properties {kind:text layer, opacity:100}

        tell text object of art layer 1

        set {contents, size, stroke color, position, justification} to {"Jarvis Photography Lake Tahoe", 13.0, {class:RGB hex color, hex value:"FFFFFF"}, {(docWidth * 0.5), (docHeight - 120)}, center}

        end tell

        set font of text object of art layer 1 to "TrajanPro-Regular"

       

        make new art layer with properties {kind:text layer, opacity:100}

        tell text object of art layer 1

        set {contents, size, stroke color, font, position, justification} to {"Unretouched Proof", 12.0, {class:RGB hex color, hex value:"FFFFFF"}, "Scala Sans Bold", {(docWidth * 0.5), (docHeight - 70)}, center}

        end tell

       

        make new art layer with properties {kind:text layer}

        tell text object of art layer 1

        set {contents, size, stroke color, font, position, justification} to {jobDescription & "  " & baseName, 10.0, {class:RGB hex color, hex value:"FFFFFF"}, "Scala Sans Regular", {(docWidth * 0.5), (docHeight - 15)}, center}

        end tell

       

        set myOptions to {class:JPEG save options, embed color profile:true, quality

        save in ((targetFolder as string) & name) as JPEG with options myOptions with copying

       

        end tell

        close the current document saving no

        end repeat

        end tell

      end timeout

       

      If anyone can help me eliminate the extra characters in the name it would be greatly appreciated. Thanks!

       

      Eric

        • 1. Re: Applescript performs differently from within Filemaker
          electon

          AppleScript in FileMaker does work in mysterious ways...

           

          I think where you're refering to the concatenation is: jobDescription & "  " & baseName

          There seems to be nothing wrong with the script.

          Possibly a text encoding mismatch between FM and Photoshop.

          Could you try with a different separator that is actually a character,  "_" underscore maybe?

          Just to see it's a character issue.

          • 2. Re: Applescript performs differently from within Filemaker
            jarvphot

            Thanks for your reply.

             

            I have tried using "_" with the same problem results.

             

            I just tested my script with longer filenames and discovered that when run through Filemaker, the script inserts "<<" before every character, for example "Test01" becomes "T<<e<<s<<t<<0<<1" so I suspect you are correct that it is a character set issue.

             

            I experimented with

              set baseName to baseName as Unicode text

            and with

              set baseName to baseName as «class utf8»

            but I get the same result.

             

            Ideas?

            • 3. Re: Applescript performs differently from within Filemaker
              jml

              I've found on many occasions that using:

              tell application "FileMaker Pro Advanced"

              end tell

              fouls things up since the script is already running from within FileMaker Pro Advanced.

               

              Have you tried removing the tell application "FileMaker Pro Advanced" and end tell lines?

              • 5. Re: Applescript performs differently from within Filemaker
                jarvphot

                Have you tried removing the tell application "FileMaker Pro Advanced" and end tell lines?

                 

                Thanks for the tip jml but unfortunately that wasn't it in this case.

                • 6. Re: Applescript performs differently from within Filemaker
                  electon

                  Can you try jobDescription & space & baseName ?

                  • 7. Re: Applescript performs differently from within Filemaker
                    jarvphot

                    electon wrote:

                     

                    Can you try jobDescription & space & baseName ?

                    there is a "<<" between every character of baseName even when I use it alone without jobDescription

                    • 8. Re: Applescript performs differently from within Filemaker
                      ch0c0halic

                      I believe the issue is in this part of the AppleScript.

                       

                      This appears to be concatenating the characters into a list. But without a delimiter defined you are getting "<<" added for each item. I'd suggest doing something else but I don't really know what you are doing here.

                       

                      My suggestion (guess) is to add this command before this segment of code:

                      Set TextItemDelimmiter to ""

                       

                      set baseName to fName

                        repeat with idx from 1 to (length of fName)

                        if (item idx of fName = ".") then

                        set baseName to (items 1 thru (idx - 1) of fName) as string

                        exit repeat

                        end if

                        end repeat

                      • 9. Re: Applescript performs differently from within Filemaker
                        jarvphot

                        set baseName to fName

                          repeat with idx from 1 to (length of fName)

                          if (item idx of fName = ".") then

                          set baseName to (items 1 thru (idx - 1) of fName) as string

                          exit repeat

                          end if

                          end repeat

                        This code gets the filename without extension. I'm happy to try some other code to achieve the same thing.

                         

                        Set TextItemDelimmiter to ""

                        Unfortunately this did not resolve the problem. Thanks for the suggestion

                        • 10. Re: Applescript performs differently from within Filemaker
                          TonyWhite

                          might be a text item delimiters issue...

                           

                          run this is the AppleScript Editor and looks at the Events pane on the bottom.

                           

                          set my_list to {"a", "b", "c"}

                           

                          set text item delimiters to ">>"

                          set my_string_with_strange_delims to my_list as string

                          log "my_string_with_strange_delims: " & my_string_with_strange_delims

                           

                          set text item delimiters to ""

                          set my_string_with_no_delims to my_list as string

                          log "my_string_with_no_delims: " & my_string_with_no_delims


                          Tony White

                          • 11. Re: Applescript performs differently from within Filemaker
                            electon

                            I don't have photoshop installed so can't test it but maybe try this:

                            I can now see that the problem is not with filemaker field data but with parsing the baseName from document name.

                             

                            set baseName to fName

                             

                            repeat with idx from 1 to (length of fName)

                              if (item idx of fName = ".") then

                              set baseName to text 1 thru (idx - 1) of fName as text

                              exit repeat

                              end if

                            end repeat

                            • 12. Re: Applescript performs differently from within Filemaker
                              ch0c0halic

                              I suggest you do it in FMP and send the values needed so you don't have to parse things out.

                              • 13. Re: Applescript performs differently from within Filemaker
                                jarvphot

                                Thank you electon, this solved it for me.

                                set baseName to fName

                                repeat with idx from 1 to (length of fName)

                                  if (item idx of fName = ".") then

                                  set baseName to text 1 thru (idx - 1) of fName as text

                                  exit repeat

                                  end if

                                end repeat

                                • 14. Re: Applescript performs differently from within Filemaker
                                  jarvphot

                                  For anyone who is interested in the finished script, this works from both inside FMP or on it's own. The script uses photoshop to resize an image and put the word Proof and the image name on the front of the photo. My version utilizes paths supplied by FMP but to avoid alias errors, this version prompts the user to select the source folder.

                                   

                                  --SET OUTPUT PATH

                                  set targetFolder to path to desktop

                                   

                                  --SELECT IMAGES FOR PROCESSING

                                  choose file of type "public.image" with prompt ¬

                                    "Select Images" with multiple selections allowed

                                   

                                  set fileList to result

                                   

                                  --CONVERT IMAGES

                                  with timeout of 60 * 60 * 24 seconds

                                    tell application "Adobe Photoshop CC 2015"

                                    set ruler units of settings to pixel units

                                    repeat with aFile in fileList

                                    open aFile showing dialogs never

                                    set background color to {class:RGB color, red:255, green:255, blue:255}

                                   

                                    tell the current document

                                   

                                    set fName to name

                                    set baseName to fName

                                   

                                    repeat with idx from 1 to (length of fName)

                                    if (item idx of fName = ".") then

                                    set baseName to text 1 thru (idx - 1) of fName as text

                                    exit repeat

                                    end if

                                    end repeat

                                   

                                    flatten

                                   

                                    if height > width then

                                    resize image height 1500

                                    else

                                    resize image width 1500

                                    end if

                                   

                                    set docHeight to height

                                    set docWidth to width

                                   

                                    make new art layer with properties {kind:normal, opacity:30}

                                    select region {{0, (docHeight - 5)}, {docWidth, (docHeight - 5)}, {docWidth, (docHeight - 52)}, {0, (docHeight - 52)}} without antialiasing

                                    fill selection with contents {class:RGB hex color, hex value:"000000"}

                                    deselect

                                   

                                    make new art layer with properties {kind:text layer}

                                    tell text object of art layer 1

                                    set {contents, size, stroke color, font, position, justification} to {"Proof " & baseName, 10.0, {class:RGB hex color, hex value:"FFFFFF"}, "Scala Sans Regular", {(docWidth * 0.5), (docHeight - 15)}, center}

                                    end tell

                                   

                                    set myOptions to {class:JPEG save options, embed color profile:true, quality: 10 }

                                    save in ((targetFolder as string) & name) as JPEG with options myOptions with copying

                                   

                                    end tell

                                    close the current document saving no

                                    end repeat

                                    end tell

                                  end timeout


                                  1 2 Previous Next