Topic: SofaControl (Applescript) and Cog

Last edited by jampe (2008-11-21 07:58:28)

Re: SofaControl (Applescript) and Cog

tell application "Cog"
    activate
    open "/Volumes/MUSIC/Music/A Fine Frenzy/One Cell In The Sea/Almost Lover.mp3"
end tell

That adds a song to the playlist. Im not great with scripts but i assume there is a way to make the file path a variable of some sort and use that. I wish i could help you more but i suck at coding.

Re: SofaControl (Applescript) and Cog

Re: SofaControl (Applescript) and Cog

Hah! I figured it out big_smile
I simply simulated all the keyboard shortcuts instead of using the Applescript commands:

(*
SofaCog by Jampe
2008

http://www.cogx.org

Mapping:
* Plus/Minus: Volume Up/Down
* Left/Right: Next/Previous track
* Play/Pause: Play/Pause

Menu:
* Menu

*)

global musicFolder
global g_shall_quit
set g_shall_quit to false

on rcActivate()
    set g_shall_quit to false
    tell application "Finder"
        try
            set musicFolder to item "Music" of home as string
            set musicFolder to POSIX path of musicFolder
        on error
            set musicFolder to POSIX path of (home as string)
        end try
    end tell
    
    ignoring application responses
        tell application "Cog"
            activate
        end tell
    end ignoring
    
    
    (* ACTIONS *)
    
    tell active sofascript of application "Sofa Control"
        -- menu actions
        make new action with properties {title:"Open...", script function:"openFile"}
        make new action with properties {title:"Toggle Random", script function:"toggleRandom"}
        make new action with properties {title:"Toggle Repeat All", script function:"toggleRepeat"}
        make new action with properties {title:"Quit", script function:"quitCog"}
    end tell
end rcActivate


(* BUTTONS *)

on rcPlus()
    -- send Command-Up Arrow to Sofa Control
    simulate keycode 126 with command
end rcPlus

on rcMinus()
    -- send Command-Down Arrow to Sofa Control
    simulate keycode 125 with command
end rcMinus

on rcLeft()
    -- send Command-Left Arrow to Sofa Control
    simulate keycode 123 with command
end rcLeft

on rcRight()
    -- send Command-Right Arrow to Sofa Control
    simulate keycode 124 with command
end rcRight

on rcPlay()
    -- send Command-p to Sofa Control
    simulate keystroke "p" with command
end rcPlay

on rcMenu()
    tell active sofascript of application "Sofa Control" to show actions
end rcMenu


(* FILE HANDLING *)

on openFile()
    choose file of type {"public.audiovisual-content", "public.folder", "dyn.ah62d4rv4ge804q5z", "dyn.ah62d4rv4ge80835r", "dyn.ah62d4rv4ge80835h", "dyn.ah62d4rv4ge81k62", "dyn.ah62d4rv4ge804450", "dyn.ah62d4rv4ge81k8k", "dyn.ah62d4rv4ge81k8mp", "dyn.ah62d4rv4ge81q55c"} from directory musicFolder display type "Media Files"
    --choose file from directory musicFolder display type "Media Files"
end openFile

on rcFileNameChosen(chosenFile)
    if (chosenFile is not "") then
        ignoring application responses
            tell application "Cog"
                open chosenFile
            end tell
        end ignoring
    end if
end rcFileNameChosen


(* FUNCTIONS *)

on toggleRandom()
    -- send Option-Command-s to Sofa Control
    simulate keystroke "s" with command and option
end toggleRandom

on toggleRepeat()
    -- send Option-Command-r to Sofa Control
    simulate keystroke "r" with command and option
end toggleRepeat

on quitCog()
    tell application "Cog"
        quit
    end tell
end quitCog

Use it if you like. I'd recommend it a lot!
SofaControl in general, that is

Last edited by jampe (2008-11-25 16:11:09)

Re: SofaControl (Applescript) and Cog

I have a hacintosh so i have no remote, lol. Applescripts can be used to skip tracks by using keyboard shortcuts. I think its something like

tell application "System Events" to keystroke "n" using {command down, control down}

That will use the default key combo to skip forward. Your way is much fancier though big_smile