How to launch a Command Line Tool from app in Swift? - swift

How does one invoke a command line tool from an app? I'd like to package the app with the command line tool and be able to launch it when the app launches.
When I try to use
func openCommandLineTool() {
NSWorkspace.shared.open(URL(fileURLWithPath: "/filepath/"))
}
It tells me the application does not have permission to launch the command line tool.
My goal is to have an app that only launches the command line tool. How can I build this command line tool into the app? Is it possible?

I solved this by going to the .entitlements file within Xcode and selecting 'NO' for both 'App Sandbox' and 'com.apple.security.files.user'.

Related

Editing an Xcode project via Terminal command

I can open one of my Xcode project in Xcode and add Application supports iTunes file sharing=Yes to plist with Xcode and through Xcode directly, Now I was wandering if this work code be done completely via Terminal as well?
My Goal is type a command in Terminal that does the same work for plist just with Terminal and without opening Xcode program and doing it manually just with Terminal command. For example I have a random Xcode project saved on my Desktop, and since Xcode is accessible via Terminal, I want make this work.
As #Sweeper already answered you should got to the path of your .plist file and then write the following command:
vim Info.plist
This will open an editor which then you need to click on "i", then input the following line into the main tag:
<key>UIFileSharingEnabled</key><true/>
Then click "esc" then ":" then "w" then "q" and finally "Enter" and you are done.

Angular ng serve asking to open app and not working

Problem Statement
When I try to do ng s -o in my terminal for my Angular app, it says, "How would you like to open this?" inside a popup box where I can choose an app, but choosing an app doesn't work.
Image of Problem
When I try to choose an app, it displays code. When I chose Chrome in the popup box, this happens:
The image shows that when I run an app after ng s -o it just displays code. Also, the tab title in the browser says "ng" when the code shows. Another thing, there is no error in the terminal...
Expected Results
I want to run my Angular app with ng s -o.
Actual Results
The app doesn't serve and asks to open an app.
Note: I am using Visual Studio Code for this.
The problem was related to my cli. I was using PowerShell when I was running ng, and for some strange reason, PowerShell stopped running ng and was asking me to open an app to run the file. Even though this never happened to me before and I was using ng and PowerShell just fine before. Strange!
Now I am using CMD instead. It now runs perfectly. So, I switched cli's from PowerShell to CMD in my integrated terminal in Visual Studio Code and it started working.
I got the idea to switch cli's from this: https://github.com/Microsoft/vscode/issues/28541
npx ng serve -o works for me in visual studio code.
The problem was caused as the Vs code was using PowerShell mode. By changing it to default cmd mode, the ng commands started to work.
The steps to change from PowerShell to cmd mode is as follows:
Press Ctrl + Shift + P to show all commands.
Type profile in the displayed text box to filter the list.
Select Terminal: Select Default Profile.
You will be prompted to select your preferred terminal shell, you can change this later in your settings or follow the same process as we do now.

How to know some app's console command in unity dash?

Is it possible to see some app's console command from unity dash menu?
For example, I open the Dash via the windows key, type in some app name, it appears in the list below, and I do "something" to see how to start it from the command line.
I am asking this because I came across multiple 3rd party apps whose console command has nothing with the app name, and I was unable to figure out how to open such apps from the console.
Navigate to this path in a file manager: /usr/share/applications
For example, with Nautilus you would run (in a terminal)
nautilus /usr/share/applications
Locate your program by name (using search if required).
Right click the file for your program.
Select 'Properties'.
There should be a 'Command' field which shows the command to be executed. If the program has arguments such as %U, those are file arguments passed when that program is used to open a file.

Applescript Xcode to clean, build and install on iPhone device

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.

Bring iPhone Simulator to front of screen on build?

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.