I have the Xcode bundle for TextMate and the Build and Run with XCode work fine but is there a way to pass Active Target, Active SDK or configuration into the build in order to launch the simulator?
I have tried setting shell vars in the prefs pane but no luck.
Thanks.
Found at http://hexperimental.com/content/coding-iphone-apps-textmate
I haven't tested this myself, but this guy suggests setting TextMate as your editor of choice in xcode and then changing the run shortcut to use applescript to send keyboard shortcuts
Open the Bundle editor ( Bundles > Bundle Editor > Show Bundle editor ), the xcode bundle is all the way down, select the Run command and change the Command to this:
osascript -e 'tell application "Xcode"
activate
end tell
tell application "System Events"
key code 15 using {command down, shift down}
key code 15 using {command down}
end tell'
#I'm leaving the old command commented below just in case.
#PROJECT=$(ruby -- "${TM_BUNDLE_SUPPORT}/bin/find_xcode_project.rb")
#if [[ -f "${PROJECT}/project.pbxproj" ]]; then
# "${TM_BUNDLE_SUPPORT}/bin/run_xcode_target.rb" -project_dir="$PROJECT"
#else
# echo "Didn't find an Xcode project file."
# echo "You may want to set TM_XCODE_PROJECT."
#fi
Related
If possible, how does one create a SwiftUI-based (not Cocoa-based) droplet app for macOS? ... and, as an extra step towards the newer Swift ecosystem, can this be done with the Swift Package Manger (SPM) instead of as an Xcode project?
An example use case, that I'm trying to figure out, is the Swift analog to the AppleScript Droplet/App which can launch multiple VLC instances. This VLC AS Droplet/App can be also used with the Finder Get Info "Open with:" setting.
on run
do shell script "open -n /Applications/VLC.app"
tell application "VLC" to activate
end run
on open theFiles
repeat with theFile in theFiles
do shell script "open -na /Applications/VLC.app " & quote & (POSIX path of theFile) & quote
end repeat
tell application "VLC" to activate
end open
The StackOverflow search "swift macos droplet" returns zero items at this time.
A general internet search ended up with "A Swift 4 ‘droplet’ scripting prototype, Dropsy" which is Cocoa based.
When I launch VSCode from the dock, it always complains that
Resolving your shell environment is taking very long. Please
review your shell configuration.
and then a bit later
Unable to resolve your shell environment in a reasonable time.
Please review your shell configuration.
According to this page, Resolving Shell Environment is Slow, the first message is displayed if .bashrc takes more than three seconds and the second is displayed if it takes longer than ten seconds.
I opened a terminal in VSCode and sourced my .bashrc file
dpatterson#dpconsulting$ time source ~/.bashrc
real 0m1.448s
user 0m0.524s
sys 0m0.671s
dpatterson#dpconsulting$
As you can see, it takes less than 1.5 seconds.
Environment:
MacOS Mojave 10.14.6
VSCode 1.53.0
Hopefully someone knows what is causing this.
Barring that, maybe someone can point me to the code that actually generates these errors.
TIA
encountered the same situation and find the issue:
https://github.com/microsoft/vscode/issues/113869#issuecomment-780072904
I extract nvm load code to the condition function ref in the issue, solved this problem:
function load-nvm {
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
}
# nvm
if [[ "x${TERM_PROGRAM}" = "xvscode" ]]; then
echo 'in vscode, nvm not work; use `load-nvm`';
else
load-nvm
fi
Open VS Code from a terminal:
code .
Restarting VSCode on BigSur works for me.
You can also check your user settings to make sure it matches the path of the shell that your terminal uses.
Check https://code.visualstudio.com/docs/supporting/troubleshoot-terminal-launch for other troubleshooting steps.
OSX Work-around
Background
If VS Code is started via an OSX (or Linux) GUI interface and there's a shell rc process that takes more than 10 seconds to complete during start-up (e.g. nvm) VS Code simply stops trying to start-up that shell.
Work-around
The two known solutions are to either get rid of the process that takes more than 10 seconds or start VS Code from the command line (i.e. code .).
This work-around is for those of us on OSX who —for whatever reason— explicitly don't/can't get rid of the 10+ second process and who —again, for whatever reason— start VS Code via the GUI.
While the following is less desirable than VS Code just having a configuration that we can change, it's still better than having to remember to run code . from the terminal, and it's much, much better than not using nvm (or switching to an alternative).
Note: The file extension does need to be changed between .command and .app several times — this is not a mistake! ;)
Create a new file with the following:
#!/bin/sh
code .
Save the file with a .command extension in your "Applications" directory, e.g. ~/Applications/vs-code-cli-starter.command.
In a terminal, change that new file's permissions:
chmod +x fileName.command
From Finder, right click-on your new app/command and select "Get Info", then repeat with your actual VS Code application.
Drag the big icon from the "Preview" section of the actual VS Code's "Get Info" to the small icon in the upper-left of your newly created app/command's "Get Info".
Close the two "Get Info" panels.
In the "Applications" directory, update the file extension from .command to .app, e.g. vs-code-cli-starter.app.
Drag the newly created app's icon to your dock.
In the "Applications" directory, swap the file extension back from .app to .command, e.g. vs-code-cli-starter.command.
Enjoy
For Linux:
if [[ "$VSCODE_PID" = "" ]]; then
echo "slow or blocking operations"
fi
Thanks to Hemisu's answer.
For those who uses zsh, .ohmyzsh and powerlevel10k prompt:
Get all your exports EXCEPT export ZSH= and nvm stuff and put them in the bottom of .zshrc file.
Insert this line at the top: if [[ "$VSCODE_PID" = "" ]]; then
Before your exports at the bottom, insert an fi (end if)
Now, all your ohmyzsh, nvm and ohmyzsh themes are not loaded when VSCode initializes (the built in terminal still works fine, with ohmyzsh).
In my case, outside that if/fi there is only exports for PATH, LDFLAGS and CPPFLAGS.
Thanks to M Imam Pratama answer.
In Linux, you can open "alacarte" and make a new shortcut with the command "code" and click the box "Open in a terminal".
Go to project location and open with code . in terminal (if you are in linux) or cmd (if you are in windows.) That should resolve this issue.
When directly opened from vscode app it happens, even I have faced this.
it's a very common error or we can say complain by vs code
so here is the solution - do not open vs code directly from its icon or directly from application instead you can do is just open vs code from terminal/cmd obviously for linux/windows respectively by typing this command -> $ code .
if this command is not working then reinstall the vs code and check all the boxes before installing it will also allows you to open vs code from folder directly by clicking right side of mouse and just click open this folder with other application and select vs code.
I'm trying to applescript XCode into building and launching on device. My script is as follows:
tell application "Xcode"
open "tmp:iphone:myproject:Project.xcodeproj"
tell project "Project"
clean
build
launch
end tell
end tell
My project consists of two targets, MainTarget and a SideTarget, the SideTarget is added as a direct dependency of MainTarget. I noticed that when my applescript runs on a pre-cleaned project (removing the build folder) only 65 files are compiled compared to when I press the "Build & Run" button in XCode 130 files are compiled.
The "launch" command in the script seems to be ignored when running the applescript - it simply does not launch on the device. The status in the bottom bar when the script is complete is "Build succeeded". What is the difference between "build" followed by "launch" compared to pressing the "Build & Run" button in the XCode top bar?
The project launches fine on device when building and running through XCode.
My main issue is that I can't get the applescript to launch on device. I do not know where things go wrong. Has anyone successfully scripted XCode to launch on device?
I've had this same problem. launch just does not work. You'll have to use debug instead.
Also, debug blocks forever, so invoke it with timeout and catch the timeout error and ignore it.
build and build and run are two separate commands within Xcode's GUI (v3.1.4 with build and go (run) and build and debug being the remainder). But the Dictionary for Xcode only shows build as being supported via Applescript. I would say both of these commands are the same as they are in the GUI, and in a perfect AS world we would see build and run in the Dictionary to make it more clear.
My question is whether launch is really building the app or just launching the previously built executable.
When I build using MonoDevelop using the MonoTouch framework it appears the iPhone Simulator always loads in the background, is there any way to bring this to the front instead of always having to click it in the dock to bring it up?
Can't find anything in preferences.
Include a compiled AppleScript in your build process:
tell application "iPhone Simulator"
activate
end tell
Create a new AppleScript file e.g. simulator.scpt and add this code:
tell application "Simulator"
activate
end tell
Compile and export as a script, optionally code sign it.
In Xcode, select the target, click + at the top, under 'Build Phases'.
Select 'New run script phase'.
In the run script, paste
osascript /<file path>/simulator.scpt
Move 'Run scripts' under 'Target dependencies'.
This will bring the simulator to the front of all windows during build or unit testing.
My company provides an eclipse based development environment which needs some environment variables setting up for the underlying toolchain so multiple versions can be installed concurrently and not take over the system.
I want to provide an icon in finder or the dock which sets these then launches eclipse so customers cannot accidentally launch eclipse without the environment being set. This is what I have tried so far:
Setting environment in Info.plist
for eclipse:
This should be a nice way to do it
but I cannot make it add to the
existing path (like export
PATH=/myapp/bin:$PATH).
bash script wrapping eclipse:
I created a bash script called
eclipse.command to set the
environment then launch eclipse.
This opens a terminal window as well
as the eclipse icon and allows
people to "Keep on dock" for the
bare eclipse. I cannot put
eclipse.command on the dock as it is
not an application.
Applescript wrapping eclipse.command:
An Applescript wrapper around
eclipse.command makes it look like
an app and prevents the terminal
window appearing. Unfortunately I
now get a dock icon for the
applescript and one for eclipse so
can still keep the bare eclipse on
the dock.
Any suggestions? Am I going about this in completely the wrong way?
There is an alternate solution which involves replacing the executable that is run by MacOS X when the user launches the Eclipse application with a shell wrapper that sets up the environment.
Create an empty text file called "eclipse.sh" in the Eclipse application bundle directory /Applications/eclipse/Eclipse.app/Contents/MacOS.
Open the eclipse.sh in a text editor an enter the following contents:
#!/bin/sh
export ENV_VAR1=value
export ENV_VAR2=value
logger "`dirname \"$0\"`/eclipse"
exec "`dirname \"$0\"`/eclipse" $#
In the example ENV_VAR1 and ENV_VAR2 are the environment variables being set up. These variables will be visible to processes launched from within Eclipse. The logger command will just log the path of the eclipse executable to the system.log as a debugging aid.
In the Terminal set the executable flag of the shell script eclipse.sh, i.e.:
chmod +x /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse.sh
Open the Eclipse.app Info.plist and change the value for the key CFBundleExecutable from eclipse to eclipse.sh.
MacOS X does not automatically detect that the Eclipse.app's Info.plist has changed. Therefore you need to force update the LaunchService database in the Terminal by using the lsregister command:
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/eclipse/Eclipse.app
The next time you launch Eclipse.app from the Dock or from the Finder the environment variables should be set.
I created the following:
alias start-eclipse='open /Applications/eclipse/Eclipse.app'
If you run start-eclipse from the command line, all env vars will be picked up. This way, you only need to maintain a single set of env vars across both command-line and eclipse environments.
Take a look at a related question: Environment variables in Mac OS X.
Basically, this involves the creation of a ~/.MacOSX/environment.plist file.
Log out and Log in for the environment.plist to get picked up by .App's
This worked perfectly in OS X Yosemite:
Open /Applications/Automator.
When the drop-down appears asking you what kind of document you want to create, choose "Application."
In the second-from-the-left list, double-click "Run Shell Script."
In the right side delete the "cat" that gets put there automatically, and replace it with this:
source ~/.bash_profile && /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse
Now go to File->Save, and save the application to your Applications directory. I named it "Eclipse" with a capital 'E' so as not to conflict with the "eclipse" directory I already had. For good measure, you can even give it the Eclipse icon by selecting the real eclipse app, pressing command-i, selecting the icon, pressing command-c, then selecting the automator "Eclipse" app, pressing command-i, selecting the icon, and pressing command-v.
Now you can open the app, or even drag it to your dock. Note that if you start it, the "real" eclipse will still show up in your dock as a separate icon, but you can't have everything. :)
sakra's answer above is awesome, except is doesn't automatically inherit your existing bash environment. To ensure eclipse.sh picks up your existing bash environment, modify eclipse.sh to use bash instead of sh and add a line to source your existing ~/.bash_profile thus:
#!/bin/bash
source ~/.bash_profile
logger "`dirname \"$0\"`/eclipse"
exec "`dirname \"$0\"`/eclipse" $#
None of the above worked for me. you have to set Eclipse -> Preferences -> Terminal -> Arguments set to --login
That will instruct Eclipse to login with your account just after opening Terminal.
See screenshot:
Reference: https://marketplace.eclipse.org/comment/4259#comment-4259
Link to Eclipse doesn't use the path set in .bashrc
Create simple script
#!/bin/bash
source /home/user/.environment_variables
/home/user/eclipse_cpp/eclipse -Duser.name="My Name"
2.
Next put your all system variables in file /home/user/.environment_variables (any file you want)
My looks like:
export COCOS_ROOT=/home/user/Projects/edukoala
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
3.
Now you can delete your variables in .bashrc and put line
source /home/user/.environment_variables
Everything works fine :)
As pointed out in https://github.com/atom/atom/issues/7045, the environment variables can be loaded automatically, without explicit source ~/.bash_profile by using
#!/usr/bin/env bash -l
instead of
#!/bin/bash
source ~/.bash_profile
after that, in both cases, follows
exec "`dirname \"$0\"`/eclipse" $#
It works great for me, thanks for all previous work.
After setting env variables in .bash_profile.
Simply open the application through terminal!
open /Application/{path/to/app}.app