Search code examples
bashshellapplescriptosx-yosemitegeektool

Peroidcly running osascript in shell script to run apple script


What I'm doing

I running a shell script periodically that checks the resolution of my screen. Based on this it will run one of two apple scripts which basically changes the visibility on another application (geek tools).

My problem

The apple scrip runs fine by its self. I understand that osascript is the way to call an apple script, Because if i try to run it directly it says it "cannot execute binary file". However when i use osascript $Home/path/smallscreen.scpt it gives me a new error:

osascript[61390:1405791] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types:  dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.  
Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.

Maybe I'm just misunderstanding something but I thought it should be straight forward to run the script from the bottom of this answer: https://stackoverflow.com/a/16071855/2522073

Claiming that you can run you apple script like this osascript /Users/USERNAME/Desktop/foo.scpt


Shell code:

rez=$(xdpyinfo | grep dimensions | awk '{print $2}' | awk -Fx '{print $1, $2}')
echo $rez> $HOME/Documents/Geeklets/Displays_temp.txt
rezold=`grep -s . $HOME/Documents/Geeklets/Displays_temp.txt`

if [ "$rezold" != "$rez" ]; then
    if [ "$rez" == "1280 777" ]; then
        osascript /Users/coolguy/Documents/Geeklets/smallscreen.scpt 
    else
        $HOME/Scripts/Geeklets/largescreen.scpt
    fi  
fi

My Apple Script:

tell application "GeekTool Helper"

    set smallGroup to group "small"
    set largeGroup to group "large"
    set defultGroup to group "Default Group"

    set visible of smallGroup to true
    set visible of largeGroup to false
    set visible of defultGroup to true  

end tell

I'm running this on a Mac 10.10.3


Solution

  • This solved my problem. https://helpx.adobe.com/photoshop/kb/unit-type-conversion-error-applescript.html

    It seems that it was some side of 32bit vs 64bit issue. Not a coding issue! Hope this ends up helping someone else.