How to create a toggle hidden file button - automator

I am trying to create a service in automator that helps me make a file/folder hidden or unhidden.
I am a very new beginner and do not know anything about automator and I have only tried putting different services together but I don't even know how they work.
I have tried the following and it is not working:
Get Selected Finder Items
Run Shell Script:
STATUS = chflags
for f in "$#"
if [$STATUS = unhidden]
then
chflags hidden
else
chflags unhidden
fi
killall Finder

You’re not all that far off: your main difficulty is how to test for whether or not the file is currently hidden. (Though your bash syntax is wrong, and a Finder-based service to toggle visibility only half makes sense -- how are you going to select a file that’s invisible?) That said, this script will work [1], given that you’re running it with bash and passing the input as arguments:
for f in "$#"
do
if ( ls -lO "$f" | grep -wq hidden )
then
chflags nohidden "$f"
else
chflags hidden "$f"
fi
done
Killing the Finder afterwards is not necessary; it will notice changes to “hidden” automatically. If you create an Automator “service” workflow, you don’t need the “Get Selected Finder Items” action at the beginning; your service will be passed the selected items as input.
[1] Mostly. It won’t work correctly on files that have “hidden” in their name. Fixing this, perhaps by using stat(1), is left as an exercise for the reader.

Related

In Fish, how do you tweak things around to match special key bindings?

Context
So I finally give a try to Fish, and as one would expect I encounter some frictions due to differences with my usual routines.
The most astonishing for me, as for many other, was the absence of the bang operator. I'm fine with the lose of sudo !!, as the suggested function replacement seems even better to me, I named it gar which means "To make, compel (someone to do something); to cause (something to be done." However I'll need a replacement for !<abc><enter> which grab the last history line starting with <abc> and run it without further ado, suggestions are welcome.
Now, for the more personal things:
- I use a Typematrix 2030 keyboard
- I use a bépo layout
- I like to configure default finger position keys with the most used actions
Aims
As on my keybord <enter> is well positioned and is semantically relevant for that, ideally I would like to achieve the following key binding:
ctrl-enter: accept the whole suggestion and run it without further confirmation
ctrl-tab: accept the whole suggestion and wait for further edit
alt-enter: redo the last command without further confirmation
But according to xev it appears that, at least with Gnome-terminal, this combinations are not recognized. Are they terminal that supports it? For now I remapped these three to <ctrl>-i, <alt>-i and <alt>-I respectively:
bind --preset \ci forward-char execute
bind --preset \ei forward-char
bind --preset \eI forward-word
This works as expected, but it seems that now the tab key will also map to the first item. I guess that tab map to <alt>-i at some point in the shell stack. I wasn't aware of that, so I don't know yet if it will be possible for Fish to separate each of them.
To manage jobs, I also came with
bind --preset \es fg
bind --preset \eS bg
The first works as expected, but the second one doesn't. With application like vim, the binding should be operated in the application configuration itself of course. But for things as trivial as yes, <alt>-S won't work as expected while <crl>-z continue to operate normally.
I also would like to bind some commands like ls -alh and git status --short to a directly executed command, showing the result bellow the currently edited line, allowing to further type seamlessly, but didn't find the way to do it yet.
Summary of remaining question
So here are my more precise questions summarised:
how do I bind the sleep signal to <alt>-S?
is there a terminal I can use where <alt>-<enter> and <ctrl>-<enter> works?
how to seamlessly run command while maintaining the current line edition in place?
can you bind something to <alt>-i without altering <tab>?
how do I bind the sleep signal to -S?
What you are doing with bind \es fg is to alter a binding inside the shell.
But when you execute yes, the shell isn't currently in the foreground, so shell bindings don't apply.
What you'd have to do instead is change the terminal settings via stty susp \cs,
but fish resets the terminal settings when executing commands (so you can't accidentally break them and end up in an unusable environment), so there currently is no way to do this in fish.
can you bind something to <alt>-i without altering <tab>?
Sure. You bind \ei. Which is escape+i, which is alt-i (because in a terminal alt is escape).
Your problem is with ctrl-i, which in the way terminals encode control+character is tab. The application receives an actual tab character, and at that point the information has been lost.
is there a terminal I can use where - and - works?
Most terminals should send \e\r for alt-enter. ctrl-enter again is unencodable with the usual code (because \r is ctrl-m), just like ctrl-tab is.
Any fix to this requires the terminal to encode these combination differently.
how to seamlessly run command while maintaining the current line edition in place?
I don't know what you mean by this. I'm guessing you want fish to remain open and editable while a command also runs in the foreground. That can't work. There's no way to synchronize output from two commands to a terminal, not with cursor movement being what it is.

Can I force applescript to run synchronously?

I'm writing a simple applescript script for iTerm2 that generates a bunch of tabs and starts running services within them (I have a lot of microservices, and all need to be running to test things locally).
Things are mostly working, however I'm experiencing some slightly odd behavior which I think is related to applescript sending commands early. Let's look at a concrete example:
create tab with default profile
tell the current session
write text "cd services/myservice"
write text "make build-docker"
write text "make run-docker"
end tell
In theory, this chunk should
1) Create a new tab
2) Change into a new directory
3) Build a docker image and
4) Run that docker image.
This will occasionally work, but more frequently I run into problems on step 4. Specifically, I'll check the tab only to find out that 'make build-docker' was the last command run. This command takes some time, so I'm assuming "make run-docker" is sent while build is running and is ignored. Is there a way to force applescript/iTerm2 to wait for this command to finish so that run is executed correctly?
Hopefully this is clear. Thanks for reading!
If you have iTerm's shell integration enabled, you can poll is at shell prompt to determine if the command has finished:
tell application "iTerm2"
tell current window
create tab with profile "BentoBox"
tell current session
write text "sleep 5"
repeat while not (is at shell prompt)
delay 0.5
end repeat
write text "sleep 5"
end tell
end tell
end tell
Otherwise, you will want to string all the commands together in one tell:
write text "cd services/myservice; make build-docker; etc; etc; etc.."
Or place them in a shell script and execute that:
write text "my_super_duper_shell_script.sh"
Or use AppleScript to write the cmds to a tmp file and execute that:
re : How can I create or replace a file using Applescript?

Finding a file in the User Library of OS X Yosemite

I wish to find a file in the lower levels of the OS X file system (Below where Spotlight searches) by content.
In other words: I know the sting abc12345 os in a text file someplace.
It could be in /Library or perhaps /Users/joe/Library or even /Users/joe/Library/Caches
How does one file the file?
I.m not sure how to use grep (or even if it the appropriate tool for the job)
Humor a newbee to the command line?
In Terminal, type
find $HOME -type f -exec grep "abc12345" {} \+
That says... starting in your HOME directory, find all things that are files (not directories) and look inside them for the string "abc12345" and print anything you find. The \+ at the end says to look in several files in one go, rather than one at a time.
If you want to read all about the find command, or any other command, type find in the Terminal, put your mouse over the word and right click, then left-click Open man Page.

Way to remove all -viewDidUnload from project's view controllers

As Apple's Official Doc said:
-viewDidUnload is deprecated in iOS 6.0. Views are no longer purged under low-memory conditions and so this method is never called.
Meanwhile, it's better to remove all -viewDidUnload implements from projects that the deployment target is iOS 6.0 or later. But removing it one by one is boring, especially you've hundreds of controllers & several projects.
So, is there any script or command that can do this batch job?
I figured out a command for Vim, I'm sure it'll make your life easier. ;)
Open Vim in desired root dir (generally, it'll be your root dir of your all controller files), press Shift : to enter command-line mode, run the command below:
:args **/*.m | argdo %s/^-\ (void)viewDidUnload\_.\{-}}\n^$\n//ge | update
This will replace all
- (void)viewDidUnload
{
[super viewDidUnload];
...
}
// a blank line here
to empty, in other words, the -viewDidUnload snippet will be removed. But note, there's a blank line after the implement. If you don't want to include it, use
:args **/*.m | argdo %s/^-\ (void)viewDidUnload\_.\{-}}//ge | update
instead.
Note: This will include lib files as well when you're in your project's root dir. I suggest go to your Controllers' root dir, then all files & you will be happy with the result. ;)
Tip:
After that, you'd better check whether all -viewDidUnload were removed, run the command below on terminal of your desired root dir:
$ find . -type f -iname "*.m" -exec grep -i "viewDidUnload" {} +
It should result with no output. Otherwise, some targets missed, you can locate it easily cause it'll list all files that not managed correctly, then just remove it manually (This might happen if your - (void)viewDidLoad is -(void)viewDidLoad without a space, or something else).
Finally, you can run
$ git diff -b --color-words
to see the result. Enjoy it! ;)
Further reading about the command
args **/*.m: Sets arglist to contain all .m files in current directory and it's subdirectories;
argdo: Run the following command(s) on all arguments in arglist;
%s/^-\ (void)viewDidUnload\_.\{-}}\n^$\n//ge: Vim RegEx to replace -viewDidUnload implement snippet to empty;
\_.: Find any character including end-of-line (linebreak).
\{-}: Match as few as possible (stopping at the first }, e.g. \{-}h will stop at the first h);
}: The last item to match;
\n: Line-break;
^$\n: blank line.
update: Save modification only if the buffer has been modified.
Reference
Search Across Multiple Lines
Search and Replace in Multiple Buffers

Setting the working directory of IPython Shell to that of the python file being executed in Canopy

I am new to IPython and I am using the Canopy distribution. The default value of the shell's working directory is /home/username. This is a bit painful, when I work on files which need other files present in the corresponding folder that I am working in.
So, I always manually change it to folder in which the file (which I am trying to execute) is present.
I found this relevant question, but my question is slightly different. Also, I couldn't understand the answer provided there really well.
Is there a shorter way of setting up the working directory of the IPython shell to that of the file on which I am working? Like a command?
Thanks for your help
You can use cd inside of iPython. cd stands for change directory
> cd /home/username/my_otherdirectory
This is a feature that is on our list of features, but quite low on priority. Canopy provides a right click context menu option to switch to the currently active editor's directory (see this).
Also, as a temporary work-around, you could use the following macro to get your job done.
# -*- coding: utf-8 -*-
def run():
code_task = get_active_task()
from os.path import dirname
def change_directory():
code_editor = code_task.active_editor
if not code_editor:
return
python_pane = code_task.python_pane
active_dir = dirname(code_editor.obj.path)
python_pane.execute_command(u'cd %s\n' % active_dir)
code_task.on_trait_change(change_directory, 'active_editor')
Note: You'll have to run this macro, each time you have closed and reopened the editor window.
See 1 and 2 for instructions on how to create a macro and for more information about macros in Canopy.
Right click on python tab in Canopy and from menu select 'Keep Directory Synced to Editor'. It will set directory containing your source file as your current working directory.You can set any directory as your working directory by selecting 'Change Working Directory' from right click menu

Resources