Author Topic: Can't get my script running  (Read 4117 times)

0 Members and 1 Guest are viewing this topic.

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Can't get my script running
« on: June 26, 2009, 05:37:27 AM »
Hi All,

Here is a script I'm trying to set to save Tiff files with LZW compression:
Quote
set TheseItems to choose file with prompt "Choisir les fichiers" with multiple selections allowed without invisibles

--on open TheseItems
tell application "Adobe Photoshop CS"
     activate
     set TiffOptions to {class:TIFF save options, embed color profile:true, image compression:LZW}
     repeat with ThisItem in TheseItems
          try
               open ThisItem
               delay 1
               save current document in file ThisItem as TIFF with options TiffOptions appending lowercase extension without copying
               close current document without saving
          on error error_message number error_number
               if the error_number is not -128 then
                    tell application "Finder"
                         activate
                         display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
                    end tell
               end if
          end try
     end repeat
end tell
--end open

But I get an error "Can't make some data into the expected type".

Why that? And above all how to fix it?
Thanks for your help!

BTW it smells like holidays around here, doesn't it?  8)
« Last Edit: June 26, 2009, 05:40:00 AM by Jean-Marie Schwartz »
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: Can't get my script running
« Reply #1 on: June 26, 2009, 06:36:59 AM »
Hi Jean-Marie,

Simply remove the word "file" from your "save" line and you should now have an uncle named Bob! ;-)

That line should be:
save current document in ThisItem as TIFF with options TiffOptions appending lowercase extension without copying

HTH
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Can't get my script running
« Reply #2 on: June 26, 2009, 07:05:36 AM »
Holidays!!! at 5.30 off home for a 2 week break. No moneys to go anywhere so some software learning and still sticking my head in other people's business here and on a couple of other forums.

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Can't get my script running
« Reply #3 on: June 29, 2009, 02:43:35 AM »
Is that that simple?  :-\
I shall give it a shot later on. Thanks in advance for I'm pretty sure it'll work  :)

I remember before leaving on Friday I discovered a shell named tiffutil. I tried this: tiffutil -lzw "13 procession.tif" -out "13 procession.tif" which was working neat from Terminal. I'd have now to make it work more widely from AS (I encountered the same issue as a while back when a full path would not be recognized  :'( ).

I'll be back with my final result of script.

Thanks again, Michel. When the solution is so simple I really feel like a newbie. That is probably what I am actually.
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Can't get my script running
« Reply #4 on: June 29, 2009, 04:30:40 AM »
I'm back with an issue I encountered some months ago but wasn't able to fix so far: shell command is not working.
Here is the code I have so far:
Quote
set TheseItems to choose file with prompt "Choisir les fichiers" with multiple selections allowed without invisibles

set FileOnePath to (first item of TheseItems) as text
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set ParentPath to text items 1 thru -2 of FileOnePath as string
set AppleScript's text item delimiters to ASTID
set FolderPath to (POSIX path of ParentPath) as string
set ChangeDirectoryShell to ("cd \"" & FolderPath & "/\"") as string

repeat with ThisItem in TheseItems
     set FileName to (name of (info for ThisItem)) as string
     set TheShellScript to ""
     set TheShellScript to ("tiffutil -lzw '" & FileName & "' -out '" & FileName & "'") as text
     do shell script (ChangeDirectoryShell)
     do shell script (TheShellScript)
end repeat

The error returned says unable to open file [FileName] when through Terminal there is no problem. Any idea why? And how to fix it? (I wonder if spaces in the file name is not a problem but I'm not sure.)

EDIT: I've tried simply passing files path straight to the shell command (do shell script "tiffutil -lzw " & (quoted form of POSIX path of ThisItem) & " -out " & (quoted form of POSIX path of ThisItem)". This works OK when I put files at the User level but it would error when files are in sub-folders  :'( At least the idea behind my script is good  :)
So what could prevent the shell command to perform correctly?
« Last Edit: June 29, 2009, 05:05:11 AM by Jean-Marie Schwartz »
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =

Offline cdms

  • Full Member
  • ***
  • Posts: 111
  • Karma: 6
  • Gender: Male
Re: Can't get my script running
« Reply #5 on: June 29, 2009, 06:13:21 AM »
The problem you have here is trying to use two do shell scripts together. Each time you use this it is like opening a new session with the Terminal. So when you run the tiff command it doesn't know that you have changed directory. Spaces in you filename should not be a problem as you have 's. You should be able to separate multiple shell script commands with ;. So first suggestion would be to replace your two commands with:

do shell script ChangeDirectoryShell & ";" & TheShellScript

This should run the two commands concurrently in a single session.


Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Can't get my script running
« Reply #6 on: June 29, 2009, 06:36:34 AM »
Thanks for your help. Unfortunately it doesn't work either. It errors the same "Can't open file" message (when there is no problem straight from Terminal).  :-\
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Can't get my script running
« Reply #7 on: June 29, 2009, 07:16:51 AM »
Aargh! It seems to be related to "special characters" (well nothing special in French but in English  :P ).
So I've tested my script on files with spaces but no accented letters in their name and it ran OK. Then on files with accented letters and it did not.

If some of you have an idea as how to solve this I'd be very very happy.
Meanwhile I'd pass my files to Renamer4Mac to remove all , , etc.  :o
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =

Offline cdms

  • Full Member
  • ***
  • Posts: 111
  • Karma: 6
  • Gender: Male
Re: Can't get my script running
« Reply #8 on: June 29, 2009, 10:15:32 AM »
Are you running Applescript 2.0? if so this may be caused by everything using Unicode Text, your accented characters can be converted to double byte.

This may seem strange but try; do shell script (quoted form of (ChangeDirectoryShell & ";" & TheShellScript))

From the applescript Language guide;

"quoted form
    Access:    read only
    Class:   text
    A representation of the text that is safe from further interpretation by the shell, no matter what its contents are. Mainly useful for passing a text string to the do shell script command."

http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_classes.html

No guarantees here but I would guess this may be why your (quoted form of POSIX path of ThisItem) worked.

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Can't get my script running
« Reply #9 on: June 29, 2009, 11:05:12 AM »
Running "version" in Script Editor I get "1.10.7". Is it right? (I'm on Mac OS X.4.11).
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =