Sunday, August 19, 2018

#1 2018-07-16 06:59:27 am

SunnyFrinton
Member
Registered: 2012-09-13
Posts: 26

Create charts with AppleScript

I am trying to create a simple bar chart in Pages/Numbers using AppleScript but cannot find how to do this. Found some code in my 'Learn AppleScript' manual but it fails to compile with the message "Syntax Error Expected end of line but found class name" highlighting the word 'chart'. Is this possible or have Apple now dropped support for this facility.
Any guidance would be gratefully received.

tell application "Pages"
    activate
    tell document 1
      add chart row names {"2008", "2009"} ¬
              column names {"Visual Basic", "Applescript"} ¬
            data {{100, 140}, {80, 200, 220}} ¬
             type "vertical_bar_2d" group by "row"
    end tell
end tell

Offline

 

#2 2018-07-16 07:29:43 am

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

Re: Create charts with AppleScript

As far as I know the command add chart is not defined in modern Pages dictionary.
I guess that you must use make.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 16 juillet 2018 15:29:38

Last edited by Yvan Koenig (2018-07-16 07:31:09 am)

Offline

 

#3 2018-07-16 07:43:31 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4623

Re: Create charts with AppleScript

Hi.

I'm afraid you're out of luck, as far as I can tell. That script was written for Pages ‘09 and has a bug anyway (three numbers instead of two in the second data list). Pages has been to all intents and purposes unscriptable since version 5.0.

When posting AppleScript code here, would you mind wrapping it in our [applescript] and [/applescript] tags? There's a button for them just above the text window on posting pages. They make the code display thus:

Applescript:

tell application "Pages"
   activate
   tell document 1
       add chart row names {"2008", "2009"} ¬
           column names {"Visual Basic", "Applescript"} ¬
           data {{100, 140}, {80, 200, 220}} ¬
           type "vertical_bar_2d" group by "row"
   end tell
end tell


NG

Online

 

#4 2018-07-16 09:11:51 am

SunnyFrinton
Member
Registered: 2012-09-13
Posts: 26

Re: Create charts with AppleScript

Thanks for reply (sorry, forgot the 

Applescript:

and

tags).
If I cannot use Pages, is there an alternative to create a chart?

Offline

 

#5 2018-08-07 03:28:29 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 286

Re: Create charts with AppleScript

It looks like Excel's Applescript Dictionary allows creation of charts.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#6 2018-08-08 09:50:40 am

kerflooey
Member
Registered: 2011-07-07
Posts: 152

Re: Create charts with AppleScript

I think the Smile osax ( http://www.satimage.fr/software/en/downloads/index.html ) still works and has scriptable drawing commands.

Offline

 

#7 2018-08-09 06:58:43 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2796
Website

Re: Create charts with AppleScript

kerflooey wrote:

I think the Smile osax ( http://www.satimage.fr/software/en/downloads/index.html ) still works and has scriptable drawing commands.



In addition to kerflooey: You can also use AppleScriptObjC and create a chart with a couple of NSRects and NSBezierPaths.

Last edited by DJ Bazzie Wazzie (2018-08-09 06:58:58 am)

Offline

 

#8 2018-08-16 05:08:06 pm

TimMurphy
Member
From:: London
Registered: 2009-01-29
Posts: 26

Re: Create charts with AppleScript

I posted some detailed stuff on this back n 2011 as well as some other excel+AppleScript stuff.
If you look at my previous posts' history you will easily spot it.
Don't know if subsequent versions of both AppleScript or Excel are now 'broken' in this regard, but it used to work fine..


Filed under: excel

Offline

 

#9 2018-08-16 08:35:20 pm

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2796
Website

Re: Create charts with AppleScript

TimMurphy wrote:

I posted some detailed stuff on this back n 2011 as well…



For the record: It's probably this post.

Offline

 

#10 2018-08-17 03:48:10 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4623

Re: Create charts with AppleScript

It turns out it's possible to create a chart in Pages's stablemate Keynote, if that's any help. I haven't yet found a way to script the result over to Pages.

Applescript:

tell application "Keynote"
   activate
   -- Make a new document whose slides have a white background. There are several on-board themes from which to choose.
   set newDoc to (make new document with properties {document theme:theme "White"})
   tell slide 1 of newDoc
       -- Hide the slide's "Double-click to edit" spiel.
       set {title showing, body showing} to {false, false}
       -- Add a chart with the required details, similarly to how it used to be possible in Pages.
       add chart row names {"2008", "2009"} ¬
           column names {"Visual Basic", "Applescript"} ¬
           data {{100, 140}, {80, 200}} ¬
           type vertical_bar_2d ¬
           group by chart row
       -- Optionally set a variable to the result.
       set newChart to chart 1
   end tell
end tell

Last edited by Nigel Garvey (2018-08-17 04:15:48 am)


NG

Online

 

#11 Yesterday 02:09:18 am

technomorph
Member
Registered: 2017-12-14
Posts: 31

Re: Create charts with AppleScript

Offline

 
pornplaybb.com shemalevids.org macromastiavideo.com

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)