Simple sample script only worked once

You can do a timed screen grab via Grab in Utils, then crop off all surrounding area other than Applescript window, with tool tip.

Then find something like bitbucket that allows uploads of images and post the URL

You can do this via Capture > Timed

Hi Jay,
here’s the contents of the tool tip rollover
‘ascr’'err '{ ‘----’:‘utxt’(“Finder got an error: The operation can’t be completed.”),‘errn’:-8082 }
Cheers
Rob

Hi Rob, can you please take a screenwhot of applescript running with events and answers, and upload the screen shoot here

http://imageshack.us/

Then post URL Here.

Also is it just the PDF in the folder you are trying to move over?

Here’s the link Jay.
http://yfrog.com/fvapplescripterrorp

Cheers Rob,

Ok, Can you do me a favour, just to check something

Can you change scripts to From - Create a Folder on Desktop called From

Can you change scripts2 to Too - as above Create a Folder called Too

In From Just Add a Text File Called Hello.txt

Then Run The Applescript

See if this is still causing an issue. I’ve compared my results of a “working” result against your screen shot and the code is working perfectly. This current applicaition is confusing me though.

I’ve tried various thin like trying to copy an running application in a folder, trying to coy over at same time, tying with different file types, i cannot replicate what you are getting :frowning:

This is My Results:

tell current application
path to desktop as text
→ “Splat Attack:Users:JBird:Desktop:”
path to desktop as text
→ “Splat Attack:Users:JBird:Desktop:”
end tell
tell application “Finder”
move every item of folder “Splat Attack:Users:JBird:Desktop:Scripts” to folder “Splat Attack:Users:JBird:Desktop:Scripts2”
→ document file “Untitled.scptd” of folder “Scripts2” of folder “Desktop” of folder “JBird” of folder “Users” of startup disk
→ error number 0
end tell
Result:
document file “Untitled.scptd” of folder “Scripts2” of folder “Desktop” of folder “JBird” of folder “Users” of startup disk of application “Finder”

the first → (under move every item in the results) changes depending on what it is going to copy, in this instance it was a file, in another if it was a folder it would say

→ Folder “name” of … etc

or application

→ Application “name” of … etc

HI Jay,
OK that works…but only the first time.
If I move the file back and try again the script no longer works.

Now if I move it back out and save another file to that folder it still doesn’t work.
Cheers
Rob

I’ve created a new folders From1 and Too1.
Again it only works the first time. This time I didn’t move the same file back but moved a different file into From1

Im off in a Min Rob,

2 Things to check

How does it run when you try it as an App → Save as , Application in Drop Down

Right click on copied file and check get info, check the sharing and permissions to make sure they are correct

Utils > Disk Utility > Macintosh HD > First Aid Verify Disk Perms / Fix if Needed. →

the only reason i’m suggesting this is all i can think of at present is the move is adding extra permission / removing permissions when it is run 1st time.

The same problem still occurs when I save as an application
Sharing and Permissions seem to be OK Read and Write for me.
Thinking that it may be the permissions of the folders I checked that as well and iare OK.
Did you want me to verify my startup disk?

can give it a go, just to tick that one of the list of things it could be.

Hi Jay,
I just got back but due to our time differences I was able to work on this a lot this morning.
I wasn’t able to solve the problem and I think the key is in the error message that was breaking down the path into single characters.
Anyhow this problem was only one step in the process.
Although I’d like to know the reason for the error - so I can understand it - I have moved on to the rest of the project.
There are 30 franchises that I need to send out reports to from Excel. I intend to email them and each report has it’s own code + yymm +“.pdf” as the filename. I’m storing them in Folder “Jul”, “Aug” etc.
Here’s the code of come up with and it’s working quite well including the part where I rename it and transfer it from the “Temp” folder.

set franchise to {"Adelaide", "Airlie Beach", "Bayside", "Cairns", "Camden", "Canberra", "Central West", "East (Brisbane) & Central", "Fraser Coast", "Gladstone / Rockhampton", "Gold Coast", "Goondiwindi", "Gosford", "Hornsby", "Ipswich", "Logan", "Mackay", "Mid North Coast  (Coffs Harbour)", "Mt Gambier", "Northern Rivers", "Northside", "Pine Rivers", "Redcliffe", "Southside", "Sunshine Coast", "Tamworth", "Toowoomba", "Townsville (Carpet)", "Tweed Coast", "Westside"}
tell application "Microsoft Excel"
	repeat with i in franchise
		open "Macintosh HD:Rob:Documents:Monthly_2010.xlsb"
		set value of cell "T2" of sheet "Report" of document 1 to i
		delay 1
		print out sheet "Report"
		
		set NewFileName to value of cell "T9" of sheet "Report" of document 1
		tell application "Finder"
			set theFolder to (path to home folder as text) & "Monthly Reports:Reports :Temp:"
			set targetFolder to (path to home folder as text) & "Monthly Reports:Reports :AUG:"
			delay 3
			set name of first file of folder theFolder to NewFileName & ".pdf"
			move (every file of folder theFolder whose name ends with ".pdf") to targetFolder
		end tell
	end repeat
end tell


I still need to do a lot including
error trapping and handling
the ability to select the month
and a neater solution handling the list (array)
emailing attachments based on the code to individual email addresses

If there are any glaring errors or traps within my code your advice would be appreciated.
Thanks for all your help.
If the light bulb comes on and I figure out what is wrong with the other script I’ll let you know.
Cheers
Rob

No probs,

Had a look over the script, looking good.

Issues:

   open "Macintosh HD:Rob:Documents:Monthly_2010.xlsb"

Is there anyway to change the open? → if you change HDisk Name / Reload MAc and call your user Robert, This script will need editing and rebuilding as it wont find the file.

 set theFolder to (path to home folder as text) & "Monthly Reports:Reports :Temp:"¨           
 set targetFolder to (path to home folder as text) & "Monthly Reports:Reports :AUG:"

Also these folders seem to be in the HOME folder, probably better to have them in the Documents folder

– set theFolder to (path to home folder as text) & "Documents: Monthly Reports:Reports :Temp:"¨

Seems to be spaces between Reports and Temp - may cause an issue

Always happy to help

  • Last idea regarding script issue, Perhaps a long shot, in Sys Prefs > Users - create a new user and try script with that user.

That’s the error Yvan was trying to correct back in post #14. In JayBird’s code .



set a to (path to home folder as text) & ":Desktop:Scripts"
set b to (path to home folder as text) & ":Desktop:Scripts2"

move every item of a to b

. every item of a means every item (ie. every character) of the text returned by (path to home folder as text) & “:desktop:Scripts” (the colon before “Desktop” shouldn’t be there, by the way). The move line should be addressed to the Finder and should include folder keywords to turn the texts into folder specifiers:


tell application "Finder" to move every item of folder a to folder b

You were wondering about the current application. In AppleScript, that’s the one running the script.

There is in fact nothing technically wrong with the script you posted at the top of this thread. Nor can I find any reference to error number -8082 (or its hexadecimal equivalent 0xE06E). Whatever’s causing the problem isn’t in the posted script.

Your script in post #33 has a Finder tell block inside a Microsoft Excel one. You should take it out of there to avoid terminology conflicts, to speed up the script, and to make it clearer to read.

Thanks Jay, I just woke up, it’s 4:45 in the morning here. (down under)
Thanks Nigel,
About your last point. How do I take it out and still use the Repeat function? When I tried that the syntax was wrong.
Cheers and thanks Rob

Hi Nigel,
Yesterday one of the things I tried was this. and it still gives that error.
It always runs once and then the next time I get the error.
Yes “From1” does have a fie in it.
If I delete the folder and then “New Folder” name it “From1” the script will work once and then when I relocate the file back in the folder it no longer works.

set a to (path to desktop folder as text) & "From1"
set b to (path to desktop folder as text) & "Too1"

tell application "Finder"
	move every item of folder a to folder b
end tell

Cheers and thanks for your help,
Rob

Put the ‘tell’ block inside the repeat instead of vice versa:

set franchise to {"Adelaide", "Airlie Beach", "Bayside", "Cairns", "Camden", "Canberra", "Central West", "East (Brisbane) & Central", "Fraser Coast", "Gladstone / Rockhampton", "Gold Coast", "Goondiwindi", "Gosford", "Hornsby", "Ipswich", "Logan", "Mackay", "Mid North Coast  (Coffs Harbour)", "Mt Gambier", "Northern Rivers", "Northside", "Pine Rivers", "Redcliffe", "Southside", "Sunshine Coast", "Tamworth", "Toowoomba", "Townsville (Carpet)", "Tweed Coast", "Westside"}

tell application "Microsoft Excel" to open "Macintosh HD:Rob:Documents:Monthly_2010.xlsb"

repeat with i in franchise
	tell application "Microsoft Excel"
		-- open "Macintosh HD:Rob:Documents:Monthly_2010.xlsb"
		set value of cell "T2" of sheet "Report" of document 1 to i
		delay 1
		print out sheet "Report"
		
		set NewFileName to value of cell "T9" of sheet "Report" of document 1
	end tell
	
	tell application "Finder"
		set theFolder to folder "Monthly Reports:Reports :Temp:" of home
		set targetFolder to folder "Monthly Reports:Reports :AUG:" of home
		delay 3
		set name of first file of theFolder to NewFileName & ".pdf"
		move (every file of theFolder whose name ends with ".pdf") to targetFolder
	end tell
end repeat

Note (if it helps) that the Finder has its own home keyword. It also has one for the desktop, so if you’re going to be using tthe Finder, you could use the Finder terms instead of the path to command. (Incidentally, where you have in your problem script (path to desktop folder as text), the word ‘folder’ is superfluous. You have to use it with some of the path to destinations, but not with the desktop. It doesn’t actually do any harm. It’s just not necessary.)

The action in the Finder tell block is a little disturbing to read, but I don’t know what situation it’s addressing. It takes some file which the Finder happens to think of as the first one in the Folder, renames it with a “.pdf” extension, and then moves all such files out of the folder. Hopefully there are some files left behind to be renamed in the following iterations of the repeat.

I’ve no idea why not. If that’s the entire script and you’re doing exactly as you describe, it should work every time. I don’t think it’s a scripting problem.

Thanks again Nigel.
I did in fact put the Tells sequentially inside the Repeat loop but got a compile error and assumed that was the cause. I am a real newbie at this stuff.
Thanks for the rewrite it’s much clearer.

Why does the first Excel Tell not require an End Tell?

My early version had this code which would have helped in your understanding the process.

tell application "Printer Setup Utility"
	set Current_Printer to name of current printer --> set a variable for the name of your current/default printer
	set current printer to printer "VipRiser"
end tell

VipRiser creates a pdf with an indeterminate numerical prefix of the filename. Hence the 3 sec delay while it creates the pdf.

The temp is just a folder that holds that one file long enough for the script to change its name and then put it where I want it top go. The only other way I could see to do it was to search for the string “monthly_2010” and change the name of that file.

Is there a way to query the user for the month and store in a variable for use in the folder name ending in the month e.g. “JUL”? The only way I could see to do this is with buttons but a dialog box with 12 buttons seems a little crazy.

Can you point me in the right direction to creating a script that would attach all files containing the id code eg E23455D to the corresponding email address. I envisage a csv
E23455D, Adelaide@mydomain.com
E12345D, AirlieBeach@mydomain.com
etc.

Thanks again Nigel especially for the informative way you posted your response.
You and Jay have been very helpful.
Cheers
Rob