Can't Change Input Method when Launching App with Admin Privileges - macos

I wrote a script using the Mac script editor on Mojave (10.14.15)
The script simply launches an application with Admin privileges:
on run
do shell script ¬
"/Applications/App.app/Contents/MacOS/App" user name "name" password "pw" with administrator privileges
quit
end run
I then saved this as an application and am able to launch successfully using it.
However the application that I launch (Anki study software) can not change the input setting, which means I am unable to type in any language except the default system language.
Note that making a similar application in script editor that launches without admin privileges works without issue,
ie:
on run
do shell script ¬
"/Applications/App.app/Contents/MacOS/App"
quit
end run
This seems to be the case no matter the app I launch, I also tried launching Sublime Text and the same thing occurs.
The issue also happens when using sudo to launch an app from terminal. So it definitely seems to be an issue with trying to launch an app as root.
I am new to working with AppleScript and MacOS. It seems the fault is with launching the application with admin privileges though. Any help would be greatly appreciated.

Related

MacOS creating launch agent in a console app not working

I know how to create a launch agent with a normal application say "myLaunchd" and setting "Application is agent" to "YES" and then copying the "myLaunchd.app" to the main app's Contens/Library/LoginItems.
But I need agents, which will be created by some scripts and the main-app's bundle-identifier will be provided through command line arguments.
I tried with a console app, tried using it as launch agent, but it doesn't work expected. I noticed that a normal app keeps running until it is closed (if "Application is agent" is set to "NO"). So to achieve similar effect I forced the console app to run-infinitely using while(1), but no luck.
Any suggestion will be appreciated.

Run a Applescript on a locked Mac by keypress or alternative options

I have an Applescript written for a specific purpose that launches an application and performs a couple of tasks. I would like to be able to run this script by pressing a key on my keyboard, however, while the Mac is locked. (Note: Mac is only locked, not "asleep")
I'm open to alternative options, if such (or more efficient) options exist.
The above scenario is my "ideal" configuration, the only thing I don't have flexibility on, is that the mac must stay locked for this process.
I have full administrative access to the Mac.
I would suggest you use ssh to "get into" your Mac while the screen is locked and then run your script from the shell. You would probably use osascript for that if it is Applescript, by the way.
In order to do this, you will need to ensure the sshd is running on your Mac by going to the Apple Menu, then System Preferences then Sharing and check the box beside Remote Login.
In order to ssh into your Mac, you could use another Mac, or a PC or the free iPhone/iPad app called Terminus which is brilliant for remotely controlling machines via ssh.
Rather than have to run a command when you log in, a technique which I often use is to have a user who can only execute a specific function and the very act of logging in does that function and then logs the user out again. So, for example, if I wanted a login that can reboot a machine, I would create a new user called reboot and instead of that user having bash in /etc/passwd as his shell, he would have /sbin/reboot as his shell. Just a thought - YMMV.
I've tried this same thing and when the Mac becomes locked, normal processing will not occur but slow to a crawl, so I had to turn my screens off instead of locking my Mac. There is no way around it.

Opening a new terminal window from so x application

I have a Mac OS X project (a game using SDL), and for debugging purposes when not running in xcode, I'd like to open up a terminal window that I can send text to and get line input from the user.
Is there a quick way to do this that doesn't involve creating a custom window (which is slightly problematic since the game uses SDL and I don't directly create windows)?
Opening up the standard OS X terminal would be fine, or even connecting to a separate terminal process and then sending output and reading input would also be OK.
The one criteria is that it needs to work when the application is run outside of xcode, or even on machines that don't have xcode installed.
I've spent the last few hours trying to Google this, but my searches are all returning unhelpful results. I'm clearing not seaching on the right keywords.
Thanks.
Actually every app has ability to interact with console, your just need to run it in a proper way (from a terminal or console)
Locate folder with your application. For XCode you can do it in a "Project Navigator" folder "Products", then for your app in context menu press "Show in Finder". For installed application it probably will be in the folder /Applications/. Let it be, for example, /Applications/MyBigProgramm.app.
Open console or terminal make cd to your app folder /Applications/MyBigProgramm.app/Contents/MacOS
There will be an executable file of your app.
Run it from console. After it stdin and stdout will be linked to your app.
Work with stdin and stdout as you want.
UPD 1
A bit of automation.
Create applescript with the following content:
tell application "Terminal" set currentTab to do script
("/Applications/MyBigProgramm.app/Contents/MacOS/MyBigProgramm")
end tell
Save your applescript either as app or script.
Run your base application ("MyBigProgramm") by starting your applescript.
Work with stdin and stdout as you want within your base application.
Watch output in the terminal, type sth in the terminal as input to your base application.

How to launch another process in sandbox on Mac?

I'd like to launch another own application by LSOpenApplication() in Sandbox on Mac.
Of course, I added a row into 'com.apple.security.temporary-exception.files.absolute-path.read-write' in an entitlements file for launching.
However, when launching, console spat out an error which is Not allowing process xxxx to launch "foo.app" because it has not been launched previously by the user.
It is able to launch without errors after launched the process manually once.
How can I launch the process even if not launch previously?
Is this no relation with sandboxing?
There are very few conditions under which you'll be able to launch another application and have the desired outcome. com.apple.security.temporary-exception.files.absolute-path.read-write doesn't gain you anything with regard to LaunchServices so you can remove that entitlement.
As a sandboxed application you are fairly limited in what you can actually sub-launch, this is an intentional behavior as launching another application is technically a violation of the sandbox model. the ways available to you are:
include an XPC Service in your application and have launchd launch it for you
you can run an application via NSTask, which will cause this application to inherit your sandbox when launched
you can launch an application by name, though from what i've seen this generally only works if the application is in your /Applications folder, i.e. -[NSWorkspace launchApplication:]
you can launch an application that encloses your app, but only if you've been SMLoginItemSetEnabled()
I'd say the osascript call works because its doing roughly the same as -[NSWorkspace launchApplication:]. none of the LS calls that accept bundle identifiers or absolute/relative paths are going to work.
Use osascript
osascript -e 'tell application "foo" to open'

Applescript couldn't start an application

I wrote a simple applescript to start to a program called "SelfControl" during startup, while I run the script with applescript editor, it launch the "SelfControl" app, but while I export the script as application, the app won't launch. I change the code to launch other app and is working fine.
I also change permission of SelfControl app to full read write access. Still no luck. Any idea what cause this?
Finally I found out what cause the problem, I named my applescript code as "SelfControl" and in my code I tell "SelfControl" to activate, which perhaps it try to launch itself than the app I want to launch.

Resources