MacOSX Give alias/symlink label color but not original file - macos

Hoi Stackoverflow,
i have a short question. Is it possible to set the label of an alias/symlink to a certain color without effecting other symlinks and the original file?
Lets say if have one main folder and different subgroups. Each subgroups contains symlinks to the files in the main folder.
I want know to color these symlinks according to some variables which is easily done with
osascript -e "tell application \"Finder\" to set label index of alias POSIX file \"$1\" to \"$2\""
Unfortunately this changes the label index of the main file as well as and the ones from all other symlinks to that particular file.
Thanks a lot in advance :-)

Related

Use highlighted file in Finder as Bash variable (Applescript, macOS 10.13)

I want to set up an applet for archiving my files in non-standard formats (e.g. non .zip/.cpgz/.tar) with only the use of Applescript and the command line versions of each format's respective tool. The last thing I need to figure out is how to get the path of the currently highlighted file in Finder via Applescript, so that I can pipe it to bash.
I've searched around a bit and can't seem to find an answer to this via search engine, or this forum. I have found and still find that Apple's documentation has about a 40/60 chance of being too sparse and/or outdated, or even simply nonexistent for any given subject, so I opt not to use it when possible. Please don't just link to an Apple documentation page, Real-world examples are always appreciated.
The target platform is macOS 10.13.2, Automator 2.8, Applescript 2.7.
There is more then one way to do it and also depends on how may Finder items are selected. Here's an example if only one item is selected in Finder:
set theTarget to POSIX path of (application "Finder"'s selection as string)
Or, if the pathname has spaces, use:
set theTarget to quoted form of POSIX path of (application "Finder"'s selection as string)
Sans the shown examples, the other ways can depend on how/where it falls in the rest of your code and whether or not more then one item is selected in Finder, however this is a place to start.
BTW If you're doing this AppleScript from bash, not Script Editor where the other examples were run, then using osascript in bash to run the same example AppleScript code shown above, with a single item selected in Finder, it would be:
theTarget="$(osascript -e "POSIX path of (application \"Finder\"'s selection as string)")"
Or:
theTarget="$(osascript -e "quoted form of POSIX path of (application \"Finder\"'s selection as string)")"

Xcode AppleScript : change label which content of variable

Here is my script :
property MyLabel : missing value
on buttonClicked_(sender)
set the plistfile_path to "~/Desktop/MY_DATA.plist"
tell application "System Events"
set p_list to property list file (plistfile_path)
-- read the plist data
set theMyDataFromPlist to value of property list item "DATA1" of p_list
end tell
end buttonClicked_
This gonna take the data I want from a plist and set in a variable (theMyDataFromPlist).
How can I print this variable on the label "MyLabel" and make the script auto refresh when the data change ?
also, when I click on the text (or another button), can I copy the value to the clipboard. (would set the clipboard to theMyDataFromPlist work?)
I also wonder is that possible to do the same with Swift?
How can I print this variable on the label "MyLabel"
Where would you like to print the variable? You can make AppleScript display a dialog:
set variable to 42
display dialog "The value of variable is " & variable
AppleScript is not designed as a terminal language, it is for UI scripting, so it's not like most scripting languages that just offer a print as where would the user see the printed value.
and make the script auto refresh when the data change ?
Not quite sure what you expect here. That your system magically runs your script whenever the content of a file changes? That's not going to happen. You can create a launchd job and have launchd monitor that file and then execute your script when the file changes; this is described here:
https://discussions.apple.com/message/13182902#13182902
But some process will have to monitor the file and if your script should do so, it has to be running all the time, non-stop. Then you could make some code run once every X seconds, checking the file last modification date and whenever that changes, re-read the plist. This polling is super ugly but the best thing that AS can do out of the box.
BTW where is the rest? You say
also, when I click on the text (or another button),
can I copy the value to the clipboard.
Which text? Which button? Sound like you have a whole application there but all you showed us are 11 lines script code. You didn't even mention that you have a whole application with a UI. Your question starts with "Here is my script", so you make it sound like this 11 lines is all that you have.
(would set the clipboard to theMyDataFromPlist work?)
Why don't you simply try it out? Pasting that line into ScriptEditor would have taken equally long than asking this question. I just tried it and it turns out that you can only set strings.
This code won't work:
-- bad code
set variable to 42
set the clipboard to variable
But this code does work:
-- good code
set variable to 42
set the clipboard to "" & variable
I also wonder is that possible to do the same with Swift?
Personally I would not even consider writing an application in AppleScript; I'd rather stop writing code before I do that. Of course this can be done in Swift or in Obj-C. Everything you can do in AS can be done in these other two languages and no, the opposite doesn't hold true.
Using Obj-C or Swift, you can also use GCD and with GCD monitoring a file for changes is easy. Just see
https://stackoverflow.com/a/11447826/15809

Perform Search on Whole Directory in Sublime Text 2?

Is there any directory-wide search functionality in Sublime for the directory currently opened in the editor?
Or optionally a search all opened files? (If this exists do the files have to be opened in a tab or just visible on the sidebar?)
Yes there is.
On Windows
CTRL + SHIFT + F
On Macintosh
CMD + SHIFT + F
The Where field in the search panel determines where to search. You can define the scope of the search in several ways.
More: https://docs.sublimetext.io/guide/usage/search-and-replace.html
In Sublime Text 3
Right click on FOLDERS Navigation bar
Choose Find in Folder
*/folder_name/*
In the "Where" section of the find-all dialogue (CtrlShift+F or ⌘Shift+F ), */folder_name/* will search folders called "folder_name" that are represented in your current session. For instance, if you have a file open with a path of C:\Users\joe\folder_name\file.js, you can use the *//* pattern to search any of those folders or combinations of folders: */joe/* and */Users/joe/* will both work. However, if you have a file like this C:\Users\timmy\folder_name\file.js that's not open, it won't search that (unless you explicitly name it, like in the next example).
C:\path\to\folder
You can also put in the absolute path to the folder you want to search. This is useful if you want to search a folder that is not represented in sublime (no files within that folder are currently open in sublime), or if you have two dirs with the same name, and you only want to search one. Personally, I never use this.
C:\path\to\folder, */folder_name/*
You can also combine them.
To answer your last question, at some point Sublime started automatically searching all open files and represented folders, but if you want to be sure you can use one or all of these variables:
<project>,<current file>,<open files>,<open folders>
You can read more about searching at the unofficial sublime documentation. Or from this post, which is similar to your own.

How to combine two image (png) files to print them in duplex using AppleScript

Right, so I'll try and explain this as clearly as possible;
As soon as two files are placed in the folder, I want a Folder Action to
print these files - got that...
but, and this is my problem. At the moment it prints the files after each other, and I want to make sure that they are printed together, duplex.
so far I've got this:
on adding folder items to this_folder after receiving added_items
do shell script "defaults write com.apple.print.custompresets com.apple.print.lastPresetPref Duplex"
tell application "Finder" to print these_items
end adding folder items to
so I reckon I need to combine/append the two files - so the printer sees them as one, and only one print job is the result, thus creating a duplex printed file :D
would be awesome if you have tips/ideas on how to solve this!
cheers!
I found a python script written by Martin Michel which will combine multiple images into one file. It should help you solve your problem... find it here. You may want to use image events to resize the images first before passing it to this script so they will fit properly on one printed page.
You could create a simple Automator Folder action, which would create a multipage PDF from the added image files, then either print it directly in Automator, or pass it on to an AppleScript in order to set your printer preferences.

BBEdit AppleScript for reformatting multiple files

I'm looking to write an Applescript which will utilize BBEdit — loop through a ton of HTML files and autoformat them (so the indentation is easier to read).
So far I have:
tell application "BBEdit"
activate
open {file "Macintosh HD:TEST DIRECTORY:testfile copy 2.html"} with LF translation
(format mode hierarchical)
beep
display alert "Finished!"
end tell
This applies the transformation to a single file, but has anyone got any suggestions how to apply this to an unknown number of HTML files?
You've almost got it; the trick is that you want to loop through the files returned by open. Thus, you need something like this:
tell application "BBEdit"
set docs to open LIST_OF_FILES with LF translation
repeat with doc in docs
-- format doc
save doc
end repeat
beep -- Or even `say "Finished!" without waiting until completion`
-- if you want your computer to talk to you
display alert "Finished!"
end tell
As you can see, all you need to do is place your formatting code inside this loop (and don't forget to save the files!); the loop will set doc to each element of the list docs in turn, and run the body with that element. If you're not sure how to select the files, one way is choose file with multiple selections allowed; this will pop up a dialog box which will allow you to select as many files as you want. To use it, just replace LIST_OF_FILES with (choose file with multiple selections allowed).
BBEdit will perform a find/replace on any group of files you want. Just hit command+shift+f to bring up Multi-File Search instead of the basic find/replace window.
If you have more than one set of find/replace commands that you need to execute at the same time, you need a Text Factory. See here for details on how to set one up: http://www.barebones.com/products/bbedit/benefitsexercise.html
Does that help?
You should use the Text Factory feature for this. Under "File > New > Text Factory". Any operation you can perform on a single file can be done on any number of files and you can save the operation for future use.

Resources