Tuesday, August 11, 2020

#1 2020-07-20 02:58:35 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 342

Outlook script not working, error: to item 1 of result

Have the following script.


Applescript:

tell application "Microsoft Outlook" to activate
delay 0.5
tell application "Microsoft Outlook"
   set selectedMsg to (current messages)
   set selectedMsg to item 1 of result
   set msgAttachment to attachments of selectedMsg
   set msgAttachment to result's item 1
   
   set attachmentName to name of msgAttachment
   set attachmentFile to ((path to desktop) & attachmentName) as text
   
   set submitfolder to "OS E:Users:e:Desktop:" as alias
   set collectionfolder to ":Volumes:Data E:Consulting F&M:Telephone Switch Record" as alias
   
   delay 1
   
   --> save message to disk before we move it
   save msgAttachment in file attachmentFile -- NB. 'file' specifier.
   
end tell

it used to work flawlessly under OS 10.13 and MSO 2011.  Stopped working under OS10.13 and MSO 365.

The error I get is:

Applescript:

error "Can’t get item 1 of {}." number -1728 from item 1 of {}

I played around with it but cannot get it to work.  Any tips?


Filed under: , outlook 365

Offline

 

#2 2020-07-20 03:20:29 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4567

Re: Outlook script not working, error: to item 1 of result

Using the variable result often introduce difficult to trace errors.

I guess that what you wanted to achieve is what is coded below.

Applescript:

tell application "Microsoft Outlook" to activate
delay 0.5
tell application "Microsoft Outlook"
   set selectedMsg to (current messages)
   log point "1" -- ADDED
   set selectedMsg to item 1 of selectedMsg -- EDITED
   set msgAttachment to attachments of selectedMsg
   log point "2"-- ADDED
   set msgAttachment to msgAttachment's item 1 -- EDITED
   
   set attachmentName to name of msgAttachment
   set attachmentFile to ((path to desktop) & attachmentName) as text
   
   set submitfolder to "OS E:Users:e:Desktop:" as alias
   set collectionfolder to ":Volumes:Data E:Consulting F&M:Telephone Switch Record" as alias
   
   delay 1
   
   --> save message to disk before we move it
   save msgAttachment in file attachmentFile -- NB. 'file' specifier.
   
end tell

Once again, the way you describe the reported error doesn't help, because we can't guess which instruction really issued it.
Here two instructions were able to return it : the two ones which I edited.
The two added log instructions would help.
If only "point 1" is logged we will know that
set msgAttachment to attachments of selectedMsg failed
If  "point 2" is logged before the crash, we will know that
set msgAttachment to msgAttachment's item 1 failed

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 20 juillet 2020 11:20:24

Offline

 

#3 2020-07-20 03:46:11 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 342

Re: Outlook script not working, error: to item 1 of result

Good morning.  I thought I had been clear, obviously not, so sorry.

This script takes an enclosed document from an email and puts it on the DT and from there in a folder.  next if trashes the file from the DT.

I ran your script and get following.

Applescript:

tell application "Microsoft Outlook"
   activate
   get current messages
       --> {}
   (*point 1*)
Result:
error "Can’t get item 1 of {}." number -1728 from item 1 of {}

Last edited by ChangeAgent (2020-07-20 03:46:26 am)

Offline

 

#4 2020-07-20 04:20:18 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4567

Re: Outlook script not working, error: to item 1 of result

It's always what you got several times when helpers got a correct behavior.

We can't guess what you really selected.
What is sure is that, from the application's point of view, nothing was selected.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 20 juillet 2020 12:19:25

Offline

 

#5 2020-07-20 04:29:43 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4567

Re: Outlook script not working, error: to item 1 of result

Applescript:

tell application "Microsoft Outlook"
activate
get current messages
end

If I read well, the code above return an empty list.
So there was no object available matching the description "current messages" when you ran your script.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 20 juillet 2020 12:29:37

Offline

 

#6 2020-07-20 06:36:35 am

CK
Member
From:: UK
Registered: 2018-11-04
Posts: 139

Re: Outlook script not working, error: to item 1 of result

Just glancing over, and noticed a malformed file path.  It sounds like the script hasn't reached this part in its execution yet, and the file path will probably self-correct.  But just for thoroughness:

Applescript:

":Volumes:Data E:Consulting F&M:Telephone Switch Record" as alias

As far as I'm aware--and I'm not particularly an expert on HFS paths--absolute file paths don't begin with a colon.  I think there's an AppleScript application (either Finder or SystemEvents) that will (or did) print paths to insertable USB drives as alias ":USB 1", for instance, but I've been told that's a no no.

The second characteristic of which I'm aware is that folder paths should end with a colon.

And, finally, absolutely file paths would typically begin with the name of the drive to which the file path relates.  So, assuming your hard drive is called "Macintosh HD", then one possible corrected form of the file path would be:

Applescript:

alias "Macintosh HD:Volumes:Data E:Consulting F&M:Telephone Switch Record:"

But it's also evident you're crossing over into another disk, so it can be shortened to this:

Applescript:

alias "Data E:Consulting F&M:Telephone Switch Record:"

Although I've just noticed your script doesn't end up using it anyway, so blah.

Offline

 

#7 2020-07-20 07:21:01 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4567

Re: Outlook script not working, error: to item 1 of result

CK wrote:

Just glancing over, and noticed a malformed file path.  It sounds like the script hasn't reached this part in its execution yet, and the file path will probably self-correct.  But just for thoroughness:

Applescript:

":Volumes:Data E:Consulting F&M:Telephone Switch Record" as alias

As far as I'm aware--and I'm not particularly an expert on HFS paths--absolute file paths don't begin with a colon.  I think there's an AppleScript application (either Finder or SystemEvents) that will (or did) print paths to insertable USB drives as alias ":USB 1", for instance, but I've been told that's a no no.

The second characteristic of which I'm aware is that folder paths should end with a colon.

And, finally, absolutely file paths would typically begin with the name of the drive to which the file path relates.  So, assuming your hard drive is called "Macintosh HD", then one possible corrected form of the file path would be:

Applescript:

alias "Macintosh HD:Volumes:Data E:Consulting F&M:Telephone Switch Record:"

But it's also evident you're crossing over into another disk, so it can be shortened to this:

Applescript:

alias "Data E:Consulting F&M:Telephone Switch Record:"

Although I've just noticed your script doesn't end up using it anyway, so blah.




HFS folder paths are often spelled with an ending colon but it's not required to get a valid pathname.

If you want to check that I am right, run this short script:

Applescript:

set p2d to path to desktop as string
set p2d to text 1 thru -2 of p2d
log p2d
p2d as alias

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 20 juillet 2020 15:20:56

Offline

 

#8 2020-07-20 07:57:39 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 342

Re: Outlook script not working, error: to item 1 of result

CK wrote:

Just glancing over, and noticed a malformed file path.  It sounds like the script hasn't reached this part in its execution yet, and the file path will probably self-correct.  But just for thoroughness:

Applescript:

":Volumes:Data E:Consulting F&M:Telephone Switch Record" as alias

As far as I'm aware--and I'm not particularly an expert on HFS paths--absolute file paths don't begin with a colon.  I think there's an AppleScript application (either Finder or SystemEvents) that will (or did) print paths to insertable USB drives as alias ":USB 1", for instance, but I've been told that's a no no.

The second characteristic of which I'm aware is that folder paths should end with a colon.

And, finally, absolutely file paths would typically begin with the name of the drive to which the file path relates.  So, assuming your hard drive is called "Macintosh HD", then one possible corrected form of the file path would be:

Applescript:

alias "Macintosh HD:Volumes:Data E:Consulting F&M:Telephone Switch Record:"

But it's also evident you're crossing over into another disk, so it can be shortened to this:

Applescript:

alias "Data E:Consulting F&M:Telephone Switch Record:"

Although I've just noticed your script doesn't end up using it anyway, so blah.




Thanks for that, I experimented with the : and no diference

Last edited by ChangeAgent (2020-07-20 07:58:06 am)

Offline

 

#9 2020-07-20 08:01:37 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 342

Re: Outlook script not working, error: to item 1 of result

Yvan Koenig wrote:

Applescript:

tell application "Microsoft Outlook"
activate
get current messages
end

If I read well, the code above return an empty list.
So there was no object available matching the description "current messages" when you ran your script.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 20 juillet 2020 12:29:37



as we used this script for about 10 years now I do nothing differently compared to before when it worked.  the email is selected (as we always did) and it gives this error.

Offline

 

#10 2020-07-20 08:15:55 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4567

Re: Outlook script not working, error: to item 1 of result

As long as you will not find what fails at this level trying to execute other instruction is just wasting time.

I have some difficulty to understand why the code

Applescript:

tell application "Microsoft Outlook" to activate
delay 0.5
tell application "Microsoft Outlook"
set selectedMsg to (current messages)
end tell

return an empty list on your machine when it return a list of messages on other users machines.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 20 juillet 2020 16:15:48

Offline

 

#11 2020-07-20 10:18:45 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 342

Re: Outlook script not working, error: to item 1 of result

I have no idea either Yvan.

Offline

 

#12 2020-07-27 05:27:52 am

ADeeg
Member
Registered: 2007-03-06
Posts: 6

Re: Outlook script not working, error: to item 1 of result

Hi AppleScript breaks with Office 16.39. Delete all Office Apps, empty trash and install the 16.38 version.

https://officecdn-microsoft-com.akamaiz … taller.pkg

Due to sandbox restrictions I think desktop is not a valid path to store. Try the downloads folder.


Armin

Offline

 

#13 2020-07-27 06:46:44 am

ChangeAgent
Member
From:: Scotland
Registered: 2008-03-07
Posts: 342

Re: Outlook script not working, error: to item 1 of result

Thanks for your reply.

I am still on 16.38 so that could not be it.  will try the tip with not using the desktop, maybe that is it.

and do not forget my script gets stuck much earlier at: set selectedMsg to item 1 of result

so DT would not be it and after testing is not it.

Last edited by ChangeAgent (2020-07-27 07:58:18 am)

Offline

 

#14 2020-07-27 10:00:42 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4567

Re: Outlook script not working, error: to item 1 of result

In fact your script fails before.

The instruction which fails is :

Applescript:

set selectedMsg to (current messages)

which is supposed to return a list of messages but return an empty list.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 27 juillet 2020 18:00:36

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)