-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.scpt
More file actions
140 lines (126 loc) · 4.37 KB
/
deploy.scpt
File metadata and controls
140 lines (126 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
-- Function to log to a file
on logMessage(msg)
set safeMsg to my escapeSingleQuotes(msg)
set timestamp to do shell script "date '+%Y-%m-%d %H:%M:%S'"
do shell script "echo '[ " & timestamp & " ] " & safeMsg & "' >> deploy.log"
end logMessage
-- Escape single quotes for shell logging
on escapeSingleQuotes(txt)
set AppleScript's text item delimiters to "'"
set parts to every text item of txt
set AppleScript's text item delimiters to "'\\''"
set escaped to parts as string
set AppleScript's text item delimiters to ""
return escaped
end escapeSingleQuotes
-- Wireless deployment script for Filebrowser iOS app
on run argv
if (count of argv) < 2 then
display dialog "Usage: osascript deploy.scpt <workspace‑path> <device‑name>"
return
end if
set projectPath to item 1 of argv
set targetDevice to item 2 of argv
logMessage("Starting wireless deployment...")
-- Activate Xcode and open project
logMessage("Activating Xcode...")
tell application "Xcode"
activate
delay 2
-- Open the project
try
open projectPath
on error
display dialog "Failed to open Xcode project. Please check the path."
return
end try
delay 5
end tell
logMessage("Xcode project opened.")
-- Ensure project window is frontmost
logMessage("Focusing Xcode window...")
tell application "System Events"
tell process "Xcode"
set frontmost to true
end tell
end tell
-- Select wireless device
logMessage("Selecting target device: " & targetDevice)
tell application "System Events"
tell process "Xcode"
try
click menu button 1 of toolbar of window 1
delay 1
click menu item targetDevice of menu 1 of menu button 1 of toolbar of window 1
delay 2
on error
display dialog "Failed to select target device. Please check the device name."
return
end try
end tell
end tell
-- Trigger build/run
logMessage("Running the project via Product > Run...")
tell application "System Events"
tell process "Xcode"
try
click menu item "Run" of menu "Product" of menu bar 1
on error
display dialog "Failed to trigger Run. Please check Xcode state."
return
end try
end tell
end tell
-- Handle Replace dialog if shown
logMessage("Checking for Replace dialog...")
delay 3
tell application "System Events"
tell process "Xcode"
try
if exists (window 1 whose name contains "Replace") then
click button "Replace" of window 1
logMessage("Clicked Replace in dialog.")
end if
end try
end tell
end tell
-- Wait for build to start
logMessage("Waiting for build to complete and app to start...")
set timeoutSeconds to 90
set elapsed to 0
set buildStarted to false
repeat until buildStarted or (elapsed > timeoutSeconds)
delay 1
set elapsed to elapsed + 1
try
tell application "System Events"
tell process "Xcode"
set stopEnabled to enabled of menu item "Stop" of menu "Product" of menu bar 1
if stopEnabled is true then
set buildStarted to true
end if
end tell
end tell
on error
-- menu not available yet, keep looping
end try
end repeat
-- Stop session and notify result
if buildStarted then
logMessage("App is running. Stopping debug session via Product > Stop...")
delay 5
tell application "System Events"
tell process "Xcode"
click menu item "Stop" of menu "Product" of menu bar 1
end tell
end tell
display notification "App successfully deployed to device!" with title "Deployment Complete"
logMessage("Deployment complete.")
else
display dialog "Build may have failed. Please check Xcode for errors."
logMessage("Build timeout or failure.")
end if
logMessage("Force quitting Xcode...")
delay 2
do shell script "pkill -9 Xcode"
end run