Debug or "Save" .app
Posted: Mon Sep 22, 2025 10:09 am
Code: Select all
-- Debug or "Save" your created app, without affecting the rest of its package contents!
-- Save this AppleScript as app. Do not use "purebasic." (with a dot) in your PB app name beginning
-- Drag it into a folder containing your PB app and the PB "compile/run" temporary app (…and your source…)
-- There must be NO other apps! (set PB prefs to "create temporary executable in source folder")
-- Run it and "Replace & Debug"! (It will ask for permissions; be sure to grant!)
-- You can open MULTIPLE DEBUG SESSIONS by clicking "Just Debug"
-- NOTE: You can use it to create the executable only once, and then always use compile/run, with or WITHOUT Debugger to "Save"
property deb : "/Applications/PureBasic.app/Contents/Resources/compilers/pbdebugger.app/Contents/MacOS/pbdebugger " -- add space
property pb : "purebasic." -- PB temp name begins with this
try
-- tell application "System Events" to set visible of application process "PureBasic" to false -- hide PB
tell application "Finder"
set dir to container of (path to me)
set nf to name of (path to me)
set myapp to 1st item of dir whose name ends with ".app" and name is not nf and name does not start with pb
set pbapp to 1st item of dir whose name ends with ".app" and name is not nf and name begins with pb
set nmyapp to characters 1 thru -5 of (name of myapp as text) as text
set npbapp to characters 1 thru -5 of (name of pbapp as text) as text
set pbapp to POSIX path of (pbapp as text) & "/Contents/MacOS/" & npbapp
set myapp to POSIX path of (myapp as text) & "/Contents/MacOS/" & nmyapp
set cp to "cp -f " & quoted form of pbapp & " " & quoted form of myapp
set dlb to button returned of (display dialog "Copy —> Replace:" & linefeed & linefeed & pbapp & "\n\n" & myapp ¬
with title "Replace " & nmyapp & "?" buttons {"Replace & Debug", "Just Debug", "Just Replace"} default button 1)
if dlb contains "Replace" then do shell script cp -- copy/replace executable
if dlb contains "Debug" then
do shell script deb & quoted form of myapp & " > /dev/null 2>&1 &" -- open with debugger
delay 0.3
tell application "System Events" to set frontmost of last application process whose name is "pbdebugger" to true
tell application "System Events" to set frontmost of last application process whose name is nmyapp to true
end if
end tell
on error e
display dialog e buttons "OOOPS!" with title "Error!" default button 1
end try