Trying to get variable result from bash terminal and store in Xcode property variable. No C experience, Xcode project is in AppleScript.
You can get the software version directly in AppleScript. The equivalent to your shell script is
set minor to (system attribute "sys2") as text
Related
I am trying to write an Automator script, that replaces a given text by some other text. I followed the steps in
Editing text in Automator
which are the same as given by a bunch of blog posts covering this topic and may vary with regards to the language the script is written in. I tried with AppleScript and with bash.
My (reduced example) bash script is:
echo hello
I have selected the option "Output replaces selected text".
I tried the script when selecting text in Xcode, TextEdit and another app. The text is not replaced (it remains the same). The script is executed - as I tested via say hello inside of the script. Also I followed the setup of:
http://www.kevincallahan.org/software/services.html
to make sure my script is enabled in "System Preferences -> Keyboard -> Shortcuts -> Services -> [√] myService", because this tool used to work on my machine and it should have the same requirements for replacing text inside a TextView like the script I am going to write. Also I read the answer:
Automator not working inside xcode
from which I could not deduct, what "give xcode access to be able to modify accessibility settings" means. I am running macOS 10.13.4.
I finally figured something out. After creating a copy of the script in the file system, the copy worked. The only difference was the name. Indeed, if I renamed the original script, it worked. The name was "resolveConflicts". I have no app in my PATH with the same name. The only place I used the same name was inside SourceTree -> Preferences -> Custom Actions. Renaming the action in SourceTree did not allow me to successfully run the script with the name "resolveConflicts". In the end I could not figure out, with which name the scripts collided. I also checked /System/Library/Services and /System/Services. No scripts with same name existed there. I sticked with a different name.
This may be a basic question. I have written a small perl script to run on a Mac running OS X which can be called from the finder by double clicking in the normal way. The file is executable and contains starts with #!/usr/bin/perl and input and output is via the clipboard. This all works but automatically opens a terminal window which the user must then close once execution is finished.
Is there an easy way to run this program as an application without opening a terminal? Can one do this with the native OS X perl? Or do I need to download something? Since the program will also be used by other users, the simpler the solution to better.
With the application "AppleScript Editor" : open it
Copy/paste this script
tell me to path to resource "this Name.pl" in directory "Scripts"
do shell script (quoted form of POSIX path of the result)
In the first line, change the name "this Name.pl" by the name of your perl file.
Save as --> Application
In the Finder :
Copy your perl file (executable) to the folder "/Contents/Resources/Scripts" of the created application
For Win32/Linux/or Mac use http://www.cavapackager.com/
If you're distributing your application to others, Platypus includes an installer to build free-standing apps around scripts.
Platypus supports Perl, Python, PHP, Ruby, Swift, Expect, Tcl, AppleScript or any other user-specified interpreter. It is free, open-source software distributed under the terms of the three-clause BSD license. It can run silently (without opening a terminal window, as you require), or can display graphical feedback of script execution as progress bar, text window with script output, droplet, WebKit HTML rendering or status item menu.
I have installed my flash application using packagemaker installer. I have created short cut to desktop using shell Script. Now i want to change the default short cut Icon. Please tell me shell script to change the short cut icon.
MAC OS 10.7.2
Mac OS X doesn't have "shortcut files". It has either alias files or symbolic links (symlinks).
I imagine that you created a symlink, since you're working from a shell. Symlinks can't have custom icons. They have almost no real data or metadata of their own.
I don't know of a way to set an icon for an alias file (or any other file) from the shell. My first thought was AppleScript, which you can use from a shell via the osascript command. But I find that the Finder's AppleScript support does not include working with file icons. There's a definition of an icon family class, but it's marked as "NOT AVAILABLE YET".
I have a shell script, which I launch several times during work everyday. I do this by launching terminal, and launching the script from within. However, I would like to be able to launch it (from within a terminal) with a global OSX keyboard shortcut (Cmd+Shift+R say).
There are quite a few applications which work in this manner already (for eg. EverNote, RemindMeLater, even the default Cmd-Space which brings up the search utility) and hence, I am guessing this should be at least theoretically possible.
Could someone please tell me if and how this can be done?
Instead of using a global shortcut key, maybe try creating an applescript that runs the shell script? So just open at AppleScript Editor, and enter something like this.
do shell script "//Your script";
Then save it as an application in the format drop down.
After that, you can run the script just by opening up the application with something like spotlight.
I like Textmate's "Sort Lines in Selection" feature a lot. Is there something similar for Xcode 4? If not, what would be the best way to integrate such a feature (a plugin, Applescript, ...)?
You can do this with Automator:
Start Automator and select either:"Service" for macOS 10.7 or"New Document" followed by "Quick Action" for macOS 11
Find and drag "Run Shell Script" into the workflow panel
Select "Output replaces selected text"
Type sort -f into the "Run Shell Script" textfield
Save
Now you can sort lines in any textfield. Select some text and right-click or Control click and select the service you just created.
After 4 years Xcode still doesn't have this feature builtin, but now it supports extensions. So here you go: "xcsort" is an extension to
sort text in Xcode 8. It adds a command to sort lines in selection.
For macOS 10.14+ (Mojave) users who are looking at epatel's answer, Automator has renamed Services to Quick Action. I was lost for a moment until I figured it out.
How
In TextMate, open the bundle and see how they have implemented it ;)
Specifically, they have used sort -f for that command.
In Xcode
Xc4 doesn't offer external commands, but Xc3 did... what version are you using?
Here's an overview for Xc3's script system: http://www.mactech.com/articles/mactech/Vol.23/23.01/2301XCode/index.html
Xc4 allows you to run an external script via Behaviours, but you cannot pass or return text/selection.
AppleScript
You may be able to do it with AppleScript... every time I have tried to do anything nontrivial with AS + Xcode, it didn't work out very reliably (if at all). But that was with Xc3 - locating what you need may be easier with Xc4 (unified UI and all).
I just use TextMate for this.
There's a bug on 10.7 and 10.8 where the shortcuts for Automator services don't always work until the services menu has been shown once from the menu bar. You can still select them from the context menu, but another option would be to assign a shortcut to a script like this:
try
set old to the clipboard as record
end try
try
tell application "System Events" to keystroke "c" using command down
do shell script "export LC_CTYPE=UTF-8; pbpaste | sort -fn | pbcopy"
tell application "System Events" to keystroke "v" using command down
delay 0.05
end try
try
set the clipboard to old
end try
Trying to get the clipboard when it's empty results in an error. pbpaste and pbcopy don't support Unicode by default in the environment used by do shell script.