Kodi Community Forum

Full Version: [Apple TV 4] Automate the refresh of Kodi and/or the Codesigning
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi,

first a few words adressed to Memphiz.

I would like to thank you for your effort, assistance and the tremendous work to bring us Kodi to the Apple TV 4.
Guy - you're incredible!

####################

So, let's start and first things first...

As the most of us i have only a free Apple Development Account. The annoying part of this solution is the 6 days refresh cycle of my provisioning profile.

I searched the Internet for a solution to automate the process, but without success. So i decided to write my own...

It's written in AppleScript and it's not perfect, but it works for me under macOS, tvOS 10 and xCode 8. So if you read further please keep in mind, it's my first project of this kind.

####################

What it does...

  1. On http://mirrors.kodi.tv/test-builds/darwin/tvos/ it checks if there's a newer version to download.

  2. If it so, it prompts for the permission to downloads it, or refresh the Codesigning of the existing one, or cancel the script

  3. If you continue it deletes the old xCode provisioning profiles in the local folder ~/Library/MobileDevice/Provisioning\ Profiles/*.mobileprovision NO PANIC! xCode downloads the new ones after you load the Kodi Project

  4. After this point it starts xCode and loads the Kodi Project which refreshes your provisioning profiles

  5. Then the iOS App Signer will start, all settings set and the Codesigning process and the build of the *.ipa file will start.

  6. In xCode the Device Manager will open, the Apple TV selected and the newly signed *.ipa file will be uploaded to your Device

  7. After the Apple TV is Ready again, the script finishes and closes all Applications.

  8. Done ...

####################

Here's the magic soup!

Code:
-- #####################################################

-- Set the path to the folder where the xCode Project and the Kodi*.deb file resists
set thePath to "/Users/efty/Documents/xCode/efty-kodi-atv4/"

-- Set the URL Source to the Kodi Test-Builds
set theKodiSource to "http://mirrors.kodi.tv/test-builds/darwin/tvos/"

-- Set the name of the Apple TV
set theAtvName to "Apple TV"

-- #####################################################

-- Get the full path of the *.xcodeproj, the *.deb and the old *.ipa files
tell application "System Events"
    set theProjectFilePath to POSIX path of (files of folder thePath whose name ends with ".xcodeproj")
    set theProjectFile to (name of files of folder thePath whose name ends with ".xcodeproj")
    set theDebFilePath to POSIX path of (files of folder thePath whose name ends with ".deb")
    set theIpaFilePath to POSIX path of (files of folder thePath whose name ends with ".ipa")
end tell

-- Retrieve the filename of the latest Kodi Test-Build
set theLatestKodi to (do shell script "curl -s '" & theKodiSource & "' --list-only | grep -o -m 1 '>kodi-.*deb' | grep -o 'kodi-.*deb'")

tell application "Finder"
    
    -- Check if this Kodi Test-Build is still the same    
    if exists (thePath & theLatestKodi) as POSIX file then
        
        -- Display a dialog when no new Kodi version is found
        display dialog "There's no new Kodi Version.

Should i refresh and update the Codesigning of the installed one?" buttons {"Cancel", "Refresh"} default button "Refresh" with icon note
        
        -- Stop the Execution if [Cancel] is pressed
        if the button returned of the result is "Cancel" then
            return
        end if
        
    else
        
        -- Display a dialog when a new Kodi version is found
        display dialog "NEW -> " & theLatestKodi & "

[Install]    = Download and install the new Version
[Refresh] = Update the existing Version" buttons {"Cancel", "Refresh", "Install"} default button "Install" with icon caution
        
        -- Stop the Execution if [Cancel] is pressed
        if the button returned of the result is "Cancel" then
            
            return
            
            -- Download and Intall if [Install] is pressed
        else if the button returned of the result is "Install" then
            
            -- Delete the old Kodi version
            if theDebFilePath is not {} then do shell script ("rm " & theDebFilePath)
            
            -- Download the new Kodi version
            do shell script ("curl -L -o " & thePath & theLatestKodi & " " & theKodiSource & theLatestKodi)
            
            -- Change the value of the Kodi variable to the new one
            set theDebFilePath to thePath & theLatestKodi
            
        end if
        
    end if
end tell

-- DELETE old Provisioning Profiles
try
    do shell script "rm ~/Library/MobileDevice/'Provisioning Profiles'/*.mobileprovision"
end try

-- DELETE the old *.ipa file
if theIpaFilePath is not {} then do shell script "rm " & theIpaFilePath

-- Open xCode
tell application "Xcode"
    
    -- open the xCode project
    open theProjectFilePath
    
    tell application "System Events"
        
        activate "Xcode"
        
        tell process "Xcode"
            
            -- Wait until the Provisioning Profile is fixed
            set theResult to "Waiting to repair..."
            repeat until theResult = ""
                set theResult to (value of static text 7 of group 2 of scroll area 1 of splitter group 1 of group 1 of splitter group 1 of group 2 of splitter group 1 of group 1 of window 1) as string
                delay 0.5
            end repeat
            
        end tell
        
        -- open AppSigner
        delay 3.0
        activate application "iOS App Signer"
        tell process "iOS App Signer"
            
            -- Enter path to 'Kodi*.deb' Input File
            set value of text field 2 of window "iOS App Signer" to theDebFilePath
            
            -- Select the Provisionig Profile
            click pop up button 2 of window "iOS App Signer"
            keystroke (ASCII character 31) -- down arrow key
            keystroke (ASCII character 31) -- down arrow key
            keystroke (ASCII character 31) -- down arrow key
            delay 0.5
            keystroke (ASCII character 3) -- enter key
            
            -- Start the Codesigning process
            click button 1 of window "iOS App Signer"
            
            -- Save the *.ipa file
            click button 1 of window "Save"
            
            -- Wait until the Codesigning process has finished
            repeat until (value of static text 6 of window "iOS App Signer" as string) contains "Done,"
            end repeat
            
            -- QUIT iOS App Signer
            tell application "iOS App Signer" to quit
            
        end tell
        
        -- Open xCode
        tell application "Xcode"
            
            tell application "System Events"
                
                activate application "Xcode"
                tell process "Xcode"
                    
                    -- Open the Devices window
                    click menu item "Devices" of menu 1 of menu bar item "Window" of menu bar 1
                    
                    -- Select 'Apple TV' device
                    set maxRow to (count rows of table 1 of scroll area 1 of splitter group 1 of window "Devices")
                    repeat with theRow from 1 to maxRow
                        if text field 1 of UI element 1 of row theRow of table 1 of scroll area 1 of splitter group 1 of window "Devices" exists then
                            if (value of text field 1 of UI element 1 of row theRow of table 1 of scroll area 1 of splitter group 1 of window "Devices") = theAtvName then
                                select row theRow of table 1 of scroll area 1 of splitter group 1 of window "Devices"
                            end if
                        end if
                    end repeat
                    
                    -- Press + Button
                    click button 4 of scroll area 1 of splitter group 1 of splitter group 1 of window "Devices"
                    
                    -- Select the *.ipa file
                    set maxRow to (count rows of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of group 1 of sheet 1 of window "Devices")
                    repeat with theRow from 1 to maxRow
                        if text field 1 of UI element 1 of row theRow of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of group 1 of sheet 1 of window "Devices" exists then
                            set theFilename to value of text field 1 of UI element 1 of row theRow of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of group 1 of sheet 1 of window "Devices"
                            if text -4 through -1 of theFilename = ".ipa" then
                                select row theRow of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of group 1 of sheet 1 of window "Devices"
                            end if
                        end if
                    end repeat
                    
                    -- Press OPEN to transfer the *.ipa file to the Apple TV
                    click button "Open" of sheet 1 of window "Devices"
                    
                    -- Wait until the transfer has finished
                    set theResult to ""
                    delay 3.0
                    repeat until (offset of "Ready" in theResult) as integer > 0
                        set theResult to (value of static text 1 of group 1 of group 2 of toolbar 1 of window 2) as string
                    end repeat
                    
                end tell
                
            end tell
            
        end tell
        
        -- QUIT Xcode
        tell application "Xcode" to quit
        
    end tell
    
end tell

display dialog "Finished..." with icon note giving up after 15

####################

I use this script since 3 weeks on daily basis, without any problems

I tried to automated the process, because my Mac is on 24/7 and the Apple TV is connected to the Mac with a long USB-Cable. So why can't the refresh of the profiles and Kodi itself not run every night!?

It will - if you remove the dialogs in my script and set it up as a cron job, everything goes like magic.
How to set up a script as a cron job can be found here: http://alvinalexander.com/blog/post/mac-...-with-cron

####################

Here is the most important part. The Kodi *.deb file, the *.ipa file and the xCode Project must be in the same folder. E. g. /Users/efty/Documents/xCode/efty-kodi-atv4/

You can set this location, the source url and the name of your Apple TV in the --#### Block at the top of my script.

####################

I think the script is well documented, so you can change it on your own. I know, there is much room for improvement. E. g. the Save dialog of the iOS App Signer stays 3 to 4 seconds and i don't know why or the selection of the provisioning profile in the iOS App Signer can be done better, instead of push the down arrow 3 times... But for now and me - it works.

So - feel free to use it or make it better. But at your own risk and without any support and guarantee!

Efty



Updates
=====
2016-10-29: (CHECK) Works with xCode 8.1
2016-12-22: {FIX} The script works now with the standard Kodi Mirrors on http://mirrors.kodi.tv/test-builds/darwin/tvos/
Is there a way to change the script to use mirrors.kodi.tv instead of the explicit german mirror server? Beside that - good work.
Hi,

i've implemented it, but in lag of another mirror not tested it.

So feel free to edit the URL at Line 7...

Code:
set theKodiSource to "ftp://ftp.halifax.rwth-aachen.de/xbmc/test-builds/darwin/tvos/"

But for me the curl code will not work with http://, only ftp://



Updated
=====
2016-12-22: {FIX} see first post
It needs to be http://mirrors.kodi.tv and nothing else as that will auto assign the correct mirror.
nah its not about me - its the fact that your code might be copied and used by others and they all will have this single mirror in the script then - drives the mirror system useless. I mean there or not so many builds atm but just imagine this would change and 20000 users let this script run on a daily base - it would be good to not hit that single server traffic wise.
@ Martijn

Hi,

i fixed the problem with the Mirror URL and updated the script in the first post to use the standard Mirror URL: http://mirrors.kodi.tv/test-builds/darwin/tvos/

Hope it's ok for you.

Efty
(2016-10-22, 17:28)efty.edge Wrote: [ -> ]@ Martijn

Hi,

i fixed the problem with the Mirror URL and updated the script in the first post to use the standard Mirror URL: http://mirrors.kodi.tv/test-builds/darwin/tvos/

Hope it's ok for you.

Efty
Very nice script. Thank you!

Do you have an updated version  for xcode 9.2 / ios 11.2 ?
Great job! I am kind of noob in this so, can this work with tvOS 11.2, Xcode 9.2 and AppleTV 4K?

Thanks!
I have tried to run it (Xcode 9.2 + ATV 4K) and it gets stuck somewhere with Xcode. Probably because the GUI is different. The problem is that I have no clue about what's trying to do in that line, nor what I should do to modify it (I'm not a Javascript developer).
I modified it to work and it does for me in 13.3 and atv4k 11.x


-- #####################################################

-- Set the path to the folder where the xCode Project and the Kodi*.deb file resists
set thePath to "/Users/Administrator/Documents/kodi-tvos/"

-- Set the URL Source to the Kodi Test-Builds
set theKodiSource to "http://mirrors.kodi.tv/test-builds/darwin/tvos/"

-- Set the name of the Apple TV
set theAtvName to "Apple TV"

-- #####################################################

-- Get the full path of the *.xcodeproj, the *.deb and the old *.ipa files
tell application "System Events"
set theProjectFilePath to POSIX path of (files of folder thePath whose name ends with ".xcodeproj")
set theProjectFile to (name of files of folder thePath whose name ends with ".xcodeproj")
set theDebFilePath to POSIX path of (files of folder thePath whose name ends with ".deb")
set theIpaFilePath to POSIX path of (files of folder thePath whose name ends with ".ipa")
end tell



-- DELETE old Provisioning Profiles
try
do shell script "rm ~/Library/MobileDevice/'Provisioning Profiles'/*.mobileprovision"
end try

-- DELETE the old *.ipa file
if theIpaFilePath is not {} then do shell script "rm " & theIpaFilePath

-- Open xCode
tell application "Xcode"

-- open the xCode project
open theProjectFilePath

tell application "System Events"

activate "Xcode"

tell process "Xcode"

-- Wait until the Provisioning Profile is fixed
set theResult to "Waiting to repair..."
repeat until theResult = ""
set theResult to (value of static text 7 of group 2 of scroll area 1 of splitter group 1 of group 1 of splitter group 1 of group 2 of splitter group 1 of window 1) as string
-- value of static text 6 of group 2 of scroll area 1 of splitter group 1 of group 1 of splitter group 1 of group 2 of splitter group 1 of window 1
delay 0.5
end repeat

end tell

-- open AppSigner
delay 3.0
activate application "iOS App Signer"
tell process "iOS App Signer"

-- Enter path to 'Kodi*.deb' Input File
set value of text field 2 of window "iOS App Signer" to theDebFilePath

-- Select the Provisionig Profile
click pop up button 2 of window "iOS App Signer"
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
delay 0.5
keystroke (ASCII character 3) -- enter key

-- Start the Codesigning process
click button 1 of window "iOS App Signer"

-- Save the *.ipa file
click button 2 of window "Save"
-- click button 1 of window "Save"

click button "Replace" of sheet 1 of window "Save"

-- Wait until the Codesigning process has finished
repeat until (value of static text 6 of window "iOS App Signer" as string) contains "Done,"
end repeat

-- QUIT iOS App Signer
tell application "iOS App Signer" to quit

end tell

-- Open xCode
tell application "Xcode"

tell application "System Events"

activate application "Xcode"
tell process "Xcode"

-- Open the Devices window
click menu item "Devices and Simulators" of menu 1 of menu bar item "Window" of menu bar 1

-- Select 'Apple TV' device
set maxRow to (count rows of outline 1 of scroll area 1 of splitter group 1 of group 1 of window "Devices")
repeat with theRow from 1 to maxRow
if text field 1 of UI element 1 of row theRow of table 1 of scroll area 1 of splitter group 1 of window "Devices" exists then
if (value of text field 1 of UI element 1 of row theRow of table 1 of scroll area 1 of splitter group 1 of window "Devices") = theAtvName then
select row theRow of table 1 of scroll area 1 of splitter group 1 of window "Devices"
end if
end if
end repeat

-- Press + Button
--click button 4 of scroll area 1 of splitter group 1 of splitter group 1 of window "Devices"
click button 4 of scroll area 1 of splitter group 1 of splitter group 1 of group 1 of window "Devices"
-- Select the *.ipa file
keystroke (ASCII character 31) -- down arrow key
delay 3.0
-- Press OPEN to transfer the *.ipa file to the Apple TV
click button "Open" of sheet 1 of window "Devices"

-- Wait until the transfer has finished
set theResult to "Apple TV"
delay 3.0
repeat while (offset of "Apple TV" in theResult) as integer = 0
set theResult to (value of static text of scroll area 1 of splitter group 1 of splitter group 1 of group 1 of window "Devices") as string
end repeat

end tell

end tell

end tell

-- QUIT Xcode
tell application "Xcode" to quit

end tell

end tell

display dialog "Finished..." with icon note giving up after 15
(2018-02-01, 19:35)xayide Wrote: [ -> ]I modified it to work and it does for me in 13.3 and atv4k 11.x
 Nope, I get the same identical error I was getting with the original script: 

error "System Events got an error: Can’t get window 1 of process \"Xcode\". Invalid index." number -1719 from window 1 of process "Xcode".

It seems to be on the line: 
Quote:set theResult to (value ofstatic text 7 ofgroup 2 ofscroll area 1 ofsplitter group 1 ofgroup 1 ofsplitter group 1 ofgroup 2 ofsplitter group 1 ofwindow 1) as string

Any idea about how to fix it? Unless it is something wrong with my Script Editor, since it also doesn't save my changes.. It is the first time I used it, so I am quite noob about all of this.
(2018-02-03, 10:02)Jecht_Sin Wrote: [ -> ]
(2018-02-01, 19:35)xayide Wrote: [ -> ]I modified it to work and it does for me in 13.3 and atv4k 11.x
 Nope, I get the same identical error I was getting with the original script: 

error "System Events got an error: Can’t get window 1 of process \"Xcode\". Invalid index." number -1719 from window 1 ofprocess "Xcode".

It seems to be on the line: 
Quote:set theResult to (value ofstatic text 7 ofgroup 2 ofscroll area 1 ofsplitter group 1 ofgroup 1 ofsplitter group 1 ofgroup 2 ofsplitter group 1 ofwindow 1) as string

Any idea about how to fix it? Unless it is something wrong with my Script Editor, since it also doesn't save my changes.. It is the first time I used it, so I am quite noob about all of this.         
I've found out what it was. I have Xcode in full screen, thus in a different space. So the script wasn't getting any windows, just the menu bar and failed. Anyway I modified the original script merging some modifications from @xayide. It works with Xcode 9.2 on macOS 11.3. I am not sure if the Mac language must be English, though. Here it is: 
Code:
-- #####################################################

-- Set the path to the folder where the xCode Project and the Kodi*.deb file resists
set thePath to "/Users/Michele/Documents/Kodi/"

-- Set the URL Source to the Kodi Test-Builds
set theKodiSource to "http://mirrors.kodi.tv/test-builds/darwin/tvos/"

-- Set the name of the Apple TV
set theAtvName to "Apple TV"

-- #####################################################

-- Get the full path of the *.xcodeproj, the *.deb and the old *.ipa files
tell application "System Events"
set theProjectFilePath to POSIX path of (files of folder thePath whose name ends with ".xcodeproj")
set theProjectFile to (name of files of folder thePath whose name ends with ".xcodeproj")
set theDebFilePath to POSIX path of (files of folder thePath whose name ends with ".deb")
set theIpaFilePath to POSIX path of (files of folder thePath whose name ends with ".ipa")
end tell

-- Retrieve the filename of the latest Kodi Test-Build
set theLatestKodi to (do shell script "curl -s '" & theKodiSource & "' --list-only | grep -o -m 1 '>kodi-.*deb' | grep -o 'kodi-.*deb'")

tell application "Finder"

-- Check if this Kodi Test-Build is still the same
if exists (thePath & theLatestKodi) as POSIX file then

-- Display a dialog when no new Kodi version is found
display dialog "There's no new Kodi Version.

Should i refresh and update the Codesigning of the installed one?" buttons {"Cancel", "Refresh"} default button "Refresh" with icon note

-- Stop the Execution if [Cancel] is pressed
if the button returned of the result is "Cancel" then
return
end if

else

-- Display a dialog when a new Kodi version is found
display dialog "NEW -> " & theLatestKodi & "

[Install] = Download and install the new Version
[Refresh] = Update the existing Version" buttons {"Cancel", "Refresh", "Install"} default button "Install" with icon caution

-- Stop the Execution if [Cancel] is pressed
if the button returned of the result is "Cancel" then

return

-- Download and Intall if [Install] is pressed
else if the button returned of the result is "Install" then

-- Delete the old Kodi version
if theDebFilePath is not {} then do shell script ("rm " & theDebFilePath)

-- Download the new Kodi version
do shell script ("curl -L -o " & thePath & theLatestKodi & " " & theKodiSource & theLatestKodi)

-- Change the value of the Kodi variable to the new one
set theDebFilePath to thePath & theLatestKodi

end if

end if
end tell

-- DELETE old Provisioning Profiles
try
do shell script "rm ~/Library/MobileDevice/'Provisioning Profiles'/*.mobileprovision"
end try

-- DELETE the old *.ipa file
if theIpaFilePath is not {} then do shell script "rm " & theIpaFilePath

-- Open xCode
tell application "Xcode"

-- open the xCode project
open theProjectFilePath

tell application "System Events"

activate application "Xcode"
delay 3.0

tell process "Xcode"

-- Wait until the Provisioning Profile is fixed
set theResult to "Waiting to repair..."
repeat until theResult = ""
delay 0.5
set theResult to (value of static text 7 of group 2 of scroll area 1 of splitter group 1 of group 1 of splitter group 1 of group 2 of splitter group 1 of window 1) as string
end repeat

end tell

-- open AppSigner
activate application "iOS App Signer"
delay 3.0
tell process "iOS App Signer"

-- Enter path to 'Kodi*.deb' Input File
set value of text field 2 of window "iOS App Signer" to theDebFilePath

-- Select the Provisionig Profile
click pop up button 2 of window "iOS App Signer"
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
keystroke (ASCII character 31) -- down arrow key
delay 0.5
keystroke (ASCII character 3) -- enter key

-- Start the Codesigning process
click button 1 of window "iOS App Signer"

-- Save the *.ipa file
click button 3 of window "Save"

-- Wait until the Codesigning process has finished
repeat until (value of static text 6 of window "iOS App Signer" as string) contains "Done,"
end repeat

-- QUIT iOS App Signer
tell application "iOS App Signer" to quit

end tell

-- Open xCode
tell application "Xcode"

tell application "System Events"

activate application "Xcode"
tell process "Xcode"

-- Open the Devices window
click menu item "Devices and Simulators" of menu 1 of menu bar item "Window" of menu bar 1

-- Select 'Apple TV' device
set maxRow to (count rows of outline 1 of scroll area 1 of splitter group 1 of group 1 of window "Devices")
repeat with theRow from 1 to maxRow
if text field 1 of UI element 1 of row theRow of table 1 of scroll area 1 of splitter group 1 of window "Devices" exists then
if (value of text field 1 of UI element 1 of row theRow of table 1 of scroll area 1 of splitter group 1 of window "Devices") = theAtvName then
select row theRow of table 1 of scroll area 1 of splitter group 1 of window "Devices"
end if
end if
end repeat

-- Press + Button
--click button 4 of scroll area 1 of splitter group 1 of splitter group 1 of window "Devices"
click button 4 of scroll area 1 of splitter group 1 of splitter group 1 of group 1 of window "Devices"
-- Select the *.ipa file
keystroke (ASCII character 31) -- down arrow key
delay 3.0
-- Press OPEN to transfer the *.ipa file to the Apple TV
click button "Open" of sheet 1 of window "Devices"

-- Wait until the transfer has finished
set theResult to "continue"
repeat until (offset of "continue" in theResult) as integer = 0
set theResult to (value of static text of scroll area 1 of splitter group 1 of splitter group 1 of group 1 of window "Devices") as string
end repeat

end tell

end tell

end tell

-- QUIT Xcode
tell application "Xcode" to quit

end tell

end tell

display dialog "Finished..." with icon note giving up after 15

Not sure how to post Applescript code in this forum...
I was able to install kodi on my apple 4k via xcode and the app signer now I want to try this script but I am not very familiar with xcode and I have now Idea how to create a apple script. Is it possible to do a step by step instruction or a video would be awesome on how to create the script using xcode.

Edit I just watched a video tutorial on apple scripting I am going to try this. Thanks
@Jecht_Sin:
I can confirm it´s working on German language macOS High Sierra, too.
Pages: 1 2