crotwell / gradle-macappbundle

A Gradle Plugin to create a Mac OSX .app application and dmg based on the project.
Apache License 2.0
94 stars 33 forks source link

backgroundImage option fails on osascript when project path contains spaces #53

Closed pskowronek closed 6 years ago

pskowronek commented 6 years ago

Hi Crotwell,

When I try to enable backgroundImage (to have /Application link) the macAppBundle task fails on osascript with the following error:

> Problem running applescript to set dmg background image: 1 335:336: syntax error: Expected „,” or „}”, but found „:”. (-2741)

I was able to dump what is being sent to osascript:

   tell application "Finder"                                                                                                                                                     
     tell disk "example-1.0.1"                                                                                                                                           
           open                                                                                                                                                                  
           set current view of container window to icon view                                                                                                                     
           set toolbar visible of container window to false                                                                                                                      
           set statusbar visible of container window to false                                                                                                                    
           set the bounds of container window to { 0, 0, pixelWidth:, pixelHeight: }                                                                                             
           set the position of the container window to {400, 100}                                                                                                                
           set viewOptions to the icon view options of container window                                                                                                          
           set arrangement of viewOptions to not arranged                                                                                                                        
           set icon size of viewOptions to 72                                                                                                                                    
           set background picture of viewOptions to file ".background:dmg-bg.png"                                                                                                
           set position of item "Example.app" of container window to { 160, 205 }                                                                                        
           set position of item "Applications" of container window to { 360, 205 }                                                                                               
           close                                                                                                                                                                 
           open                                                                                                                                                                  
           update without registering applications                                                                                                                               
           delay 2                                                                                                                                                               
        end tell                                                                                                                                                                 
     end tell

Apparently, the invocation of sips in MacAppBundlePlugin#createCopyBackgroundImageTask may return unexpected number of separators and tokenize()[2] may hit at wrong fragment resulting in "pixelWidth:" and "pixelHeight:" being sent to osascript. This will happen when the project is on the path which contains spaces (for example: /Users/doe/my projects/project) and the image path given to sips is also printed and it interferes with tokenizer.

I would suggest to replace:

imageWidth = imageWidth.tokenize()[2];

with:

imageWidth = imageWidth.tokenize().last();

if you still want to use tokonize for it.

Pull request provided.

Versions: