2013-09-10 54 views
0

以下脚本在AppleScript编辑器中运行时,将以页面上的对象的自动类型形式返回文本。但是,从PowerPoint内的AppleScript菜单运行时,它将返回一个脚本常量。PowerPoint AppleScript菜单给出与AppleScript编辑器不同的结果

我使用的这一个更复杂的版本发送基于什么汽车形状的类型,你的对象不同的应用程序的性能...表去一个地方,另一个占位符,和矩形等第三。我也从PPT中启动了这个功能来推出数据,并且无法真正从其他任何应用程序中提取它,所以AppleScript菜单将会是我想要的。

谁能告诉我为什么相同的脚本给出了两个结果?

谢谢, 亚历

tell application "Microsoft PowerPoint" 
    set currentSlideNumber to slide index of slide range of selection of document window 1 
    set theSlide to slide currentSlideNumber of active presentation 
end tell 

getProperty(theSlide) 

to getProperty(theSlide) 
    tell application "Microsoft PowerPoint" 
     repeat with thisShape in (get every shape of theSlide) 
      set shapeType to shape type of thisShape 
      set shapeContent to content of text range of text frame of thisShape 
      display alert (shapeType as string) 
    end repeat 
end tell 

端的getProperty

回答

0

转换常数(或标准的AppleScript不理解应用程序的属性),以文本是棘手的。我的猜测是,当在脚本菜单中脚本能够更好地理解这个常量,因此你可以看到它。

在任何情况下,我都遇到了与Finder常量相同的问题,并决定使用if语句处理将文本转换为文本。这是一个麻烦的解决方案,因为你必须考虑每一个常量,但至少你知道它会正确地发生。

下面是一个例子。假设有一个形状常数“rect”代表一个矩形,“circ”代表一个圆形。

注意:您可以使用实际属性的名称而不是代码中的常量。

to getProperty(theSlide) 
    tell application "Microsoft PowerPoint" 
     repeat with thisShape in (get every shape of theSlide) 
      set shapeType to shape type of thisShape 
      if shapeType is <<rect>> then 
       set shapeTypeText to "rectangle" 
      else if shapeType is <<circ>> then 
       set shapeTypeText to "circle" 
      end if 

      set shapeContent to content of text range of text frame of thisShape 

      display alert (shapeTypeText) 
     end repeat 
    end tell 
end getProperty 
+0

不幸的是,无论对象的形状类型如表格,矩形,文本框还是梯形,PPT调用的脚本都会在警报中显示“constant ****å”。你的脚本是否有效?当我试图保存它时,除非我添加引号,否则它不会编译<>。 – inaneAlex

+0

这只是一个例子来向你展示这个想法。 <>和<>是您需要放置常量的位置。我实际上没有尝试一个脚本。这个想法很重要。然后你接受这个想法并使其工作。您需要查看Powerpoint的applescript字典以查找可能的形状类型。 – regulus6633