Combining two scripts into one.

Hello,

OK…I have two scripts I am trying to now combine into one.

One script is a folder action that when a PDF File is dropped into it, that it sends and email message to a group of addresses and lets them know the name of the PDF file that was just put in the folder.

The other script is for a filemaker pro database that opens a file (in this case a pdf) in photoshop (once it is dropped on its script application icon), and adds it as a new record to to my open database after it changes its file size and copy and pastes it into the database picture field.

So, here is my thought… I would love a folder action that when a file is dropped into that folder, that it does what the second script does, makes the smaller version and copies and pastes it into the databases picture field after it creates a new record, leaving the high res PDF untouched and then have the email alert happen once it is in the database to let them know to look at it for review.

Trying to combine these two steps…see the two datbases below to see how they are are writtien now as they are working independently.

email script:

on adding folder items to this_folder after receiving these_items
repeat with i in these_items
set fileName to name of (info for i)
tell application “Mail”
tell (make new outgoing message with properties ¬
{to recipient:"Barbara.press@tiffany.com, barbarapress@mac.com ", subject:fileName, content:fileName & " has been added to folder " & this_folder as text})
send
end tell
end tell
end repeat
end adding folder items to

filemaker and photoshop script:

on open theFiles
beep
if class of theFiles is not list then
set theFiles to theFiles as list
end if

tell application "Adobe Photoshop CS3"
	set display dialogs to never
	close every document saving no
end tell

repeat with thisFile in theFiles
	tell application "Finder"
		set filePath to thisFile as alias
		set fileName to name of thisFile
		set dateMod to modification date of thisFile
	end tell
	--I added this line below to capture the modification date
	set daMonth to (month of dateMod as integer) as string
	set daDay to day of dateMod as string
	set daYear to year of dateMod as string
	set dateMod to daMonth & "/" & daDay & "/" & daYear
	
	tell application "FileMaker Pro Advanced"
		tell database "PDF Approval"
			set newRecordID to create new record at the end
			go to the last record
		end tell
	end tell
	
	tell application "Adobe Photoshop CS3"
		activate
		open filePath
		tell document 1
			set docHeight to height
			set docWidth to width
			set docName to name
			if (mode is not RGB) then
				change mode to RGB
			end if
			resize image width 400.0 as pixels
			flatten
			select all
			copy
			close saving no
		end tell
	end tell
	
	tell application "FileMaker Pro Advanced"
		activate
		tell database "PDF approval"
			tell current record
				--go to field "picture" --of the current record
				go to cell "picture"
				paste
			end tell
			tell database 1
				tell window 1
					set tableName to name of current table
					set recID to ID of current record
				end tell
				do script FileMaker script "Commit Record"
				tell table tableName
					tell record ID recID
						set cell "name" to fileName
						--I added this line below to put the modification date into FMP
						set cell "dateModified" to dateMod
						--end tell
					end tell
				end tell
			end tell
			
		end tell
	end tell
end repeat

end open

any thoughts on how to combine this would be great!!!
thanks
barbara

This just adds a global variable to store a list of the files as they are being processed, then sends the list after everything else is done.

on open theFiles
global emailList
    beep
set emailList to {}
    if class of theFiles is not list then
        set theFiles to theFiles as list
    end if
   
    tell application "Adobe Photoshop CS3"
        set display dialogs to never
        close every document saving no
    end tell
   
    repeat with thisFile in theFiles
        tell application "Finder"
            set filePath to thisFile as alias
set end of emailList to (filePath as string)
            set fileName to name of thisFile
            set dateMod to modification date of thisFile
        end tell
        --I added this line below to capture the modification date
        set daMonth to (month of dateMod as integer) as string
        set daDay to day of dateMod as string
        set daYear to year of dateMod as string
        set dateMod to daMonth & "/" & daDay & "/" & daYear
       
        tell application "FileMaker Pro Advanced"
            tell database "PDF Approval"
                set newRecordID to create new record at the end
                go to the last record
            end tell
        end tell
       
        tell application "Adobe Photoshop CS3"
            activate
            open filePath
            tell document 1
                set docHeight to height
                set docWidth to width
                set docName to name
                if (mode is not RGB) then
                    change mode to RGB
                end if
                resize image width 400.0 as pixels
                flatten
                select all
                copy
                close saving no
            end tell
        end tell
       
        tell application "FileMaker Pro Advanced"
            activate
            tell database "PDF approval"
                tell current record
                    --go to field "picture" --of the current record
                    go to cell "picture"
                    paste
                end tell
                tell database 1
                    tell window 1
                        set tableName to name of current table
                        set recID to ID of current record
                    end tell
                    do script FileMaker script "Commit Record"
                    tell table tableName
                        tell record ID recID
                            set cell "name" to fileName
                            --I added this line below to put the modification date into FMP
                            set cell "dateModified" to dateMod
                            --end tell
                        end tell
                    end tell
                end tell
               
            end tell
        end tell
    end repeat
        tell application "Mail"
            tell (make new outgoing message with properties ¬
                {to recipient:"Barbara.press@tiffany.com, barbarapress@mac.com ", subject:PDFs for review, content:"The following files have been added:" & return &  emailList})
                send
            end tell
        end tell
end open


Model: MacBookPro
Browser: Firefox 3.0.6
Operating System: Mac OS X (10.4)

hello,

OK…I saved your script in my Scripts/Folder action scripts…and attached it to a folder.
But when I drop something in the folder nothing happens…
any thoughts.??
thanks so much for your help in advance.
barbara

Try this. I can not test fully as I do not have FM or CS.

The folder action should tell the droplet to run using the file dropped in the folder.

In the file make adobe resize app. there is a on open, which should still resize a file if its dropped on to it.
But there is also a on run that will run when your folder action sends (in effect) the file to it.
The actuall gubbins of the file make adobe resize app is placed in a sub routine so as to not have to write it twice in the same script.

Change the “/Users/USERNAME/filemakeAdobeSCript.App” in the folder action script to the path of the second script/app

on adding folder items to this_folder after receiving these_items
set yourOpenviafilemakeAdobeSCriptAppPath to "/Users/USERNAME/filemakeAdobeSCript.App"
repeat with i from 1 to number of items in these_items
	set this_item to item i of these_items
	set fileName to name of (info for this_item)
	 tell application "Mail"
			tell (make new outgoing message with properties ¬
				{to recipient:"Barbara.press@tiffany.com, barbarapress@mac.com ", subject:fileName, content:fileName & " has been added to folder " & this_folder as text})
				send
			end tell 
		end tell 
	run script (POSIX file yourOpenviafilemakeAppPath) with parameters (this_item as string)
end repeat
end adding folder items to
on open theFiles
	my runnApp(theFiles)
	
end open
on runnApp(theFiles)
	global emailList
    beep
set emailList to {}
    if class of theFiles is not list then
        set theFiles to theFiles as list
    end if
   
    tell application "Adobe Photoshop CS3"
        set display dialogs to never
        close every document saving no
    end tell
   
    repeat with thisFile in theFiles
        tell application "Finder"
            set filePath to thisFile as alias
set end of emailList to (filePath as string)
            set fileName to name of thisFile
            set dateMod to modification date of thisFile
        end tell
        --I added this line below to capture the modification date
        set daMonth to (month of dateMod as integer) as string
        set daDay to day of dateMod as string
        set daYear to year of dateMod as string
        set dateMod to daMonth & "/" & daDay & "/" & daYear
       
        tell application "FileMaker Pro Advanced"
            tell database "PDF Approval"
                set newRecordID to create new record at the end
                go to the last record
            end tell
        end tell
       
        tell application "Adobe Photoshop CS3"
            activate
            open filePath
            tell document 1
                set docHeight to height
                set docWidth to width
                set docName to name
                if (mode is not RGB) then
                    change mode to RGB
                end if
                resize image width 400.0 as pixels
                flatten
                select all
                copy
                close saving no
            end tell
        end tell
       
        tell application "FileMaker Pro Advanced"
            activate
            tell database "PDF approval"
                tell current record
                    --go to field "picture" --of the current record
                    go to cell "picture"
                    paste
                end tell
                tell database 1
                    tell window 1
                        set tableName to name of current table
                        set recID to ID of current record
                    end tell
                    do script FileMaker script "Commit Record"
                    tell table tableName
                        tell record ID recID
                            set cell "name" to fileName
                            --I added this line below to put the modification date into FMP
                            set cell "dateModified" to dateMod
                            --end tell
                        end tell
                    end tell
                end tell
               
            end tell
        end tell
    end repeat
        tell application "Mail"
            tell (make new outgoing message with properties ¬
                {to recipient:"Barbara.press@tiffany.com, barbarapress@mac.com ", subject:PDFs for review, content:"The following files have been added:" & return &  emailList})
                send
            end tell
        end tell
end runnApp
on run (theFiles)
	my runnApp(theFiles)
	
end run

**Edited. Forgot to uncomment some of the script before posting. Which would have stopped it working. Now fixed

Hello,
Thanks but that didn’t work either…I have read the script that Bebout sent and it seems like it should work…
I don’t understand what the variable actually means, but reading it does seem to make sense.
However, when I drop it onto the folder that has it attached, nothing happens at all… No errors nothing.
Any more suggestions, I feel it is so close…
thanks
barbara

hello,
I actually took the script to my office and tried it with entourage, where I originally used the mail script and still nothing.
I drop it on the folder with the new script and nothing happens…
I don’t know enough about variables or how that open run is supposed to work to try and figure it out.
If you could take a look another look at it I would appreciate it…
thanks again…
Barbara

save the script as an application to make it a droplet. then drop the files on it. post and let us know if that gets the results you want.

hello,

I did try it that, but got an error that says object not found…however, I am working at a handicap here…I am trying to find a machine to mirror mine at home…

I had to change a few things as I am working on an older version of filemaker pro (and not advanced), as well as entourage and not mail…
So, I had to remove the table options, change the applications, which was not a concern, but it was asking me to remove colons for the entourage part and replace with “,” or “{”, which I did. But, I still get that message, so I am trying to find a machine that has our original specifications to see where we are really at.

Worst case scenario, I may have to wait till later tonight when I get home after 7:30pm est.
Will keep you posted…
thanks so much!! Will be back as soon as I have something for you!
barbara

ok…I found a machine that was as mine except for the entourage part…
It is still asking me to change the “:”'s to either “,” or “}”, which is odd, cause there were colons in the original email part of the script.
So, still getting the object not found error… and the odd request in entourage to replace the colons… In the end, it is entourage that I will be using, not the mac mail I was playing with on my home machine. But, the original part one of my script was tested on entourage.

thanks so much!!
barbara

Here is a thought…
Is there a way to keep the original two scrips I have and just be able to tell one to start when the other is finished?
Rather than try to combine them??? It was just a thought.
barbara

You can absolutely have one call the other. Add the bold line below between the last end tell and end repeat of the photoshop script. The path should be to the email script. ~ Michelle

    end tell

run script alias “yourDisk:yourFolder:yourScript.scpt”
end repeat
end open

Model: MacBookPro
Browser: Firefox 3.0.6
Operating System: Mac OS X (10.4)

I am sure as you have it here, that will not work.
How will the second script know what file to processes
See my post #4

This is what I was doing in post #4, plus allowing you to keep the second script as a droplet so you can use it that way also.

But I realised why it did not work for you. I commented out some of the first script while I was testing. And forgot to
uncomment it before I posted.

That is now Fixed in the script in post #4.