I am trying to do the following
tell application "Finder"
open location "smb://user:password#filesystem/folder"
end tell
However the password has a '<' in it and it seems to break the whole command. Running the script does nothing. When I remove the '<' the script runs but of course the logon fails. I tried doing \< but it didn't work. Any ideas?
It's Finder not understanding what to do with the URL. If you escape the < with %3c, it will work. Also, if you're connecting to a Windows computer or otherwise have to provide a domain name with the user, do it like smb://domain;user:password#host/share. I learned about this from this page.
Related
I am trying to make a zsh function that I can pass an argument to in order to quit a given app using the terminal in the same way that the app quits with the <CMD,Q> shortcut (so not just pkill).
I used the example of how to quit apps in macOS terminal from here and I confirmed that my Zsh function/argument use syntax seems correct from looking at this question and this documentation
quitapp() {
osascript -e 'quit app ${1:?"The application must be specified."}'
}
However, I tested it by trying to quit Spotify but when I tried to do so like this:
quitapp Spotify
I got this error:
9:10: syntax error: Expected expression, property or key form, etc. but found unknown token. (-2741)
(I tried using both lowercase and uppercase, and tried to enclose Spotify in double quotes or without double quotes, and always the same error).
What am I doing wrong?
While struggling some more I stumbled upon this and I recognize that my mistake was thinking that string would be evaluated as shell code before being passed.
But I can just solve my question with (credit to the SO answer I linked to):
qapp() {
osascript -e "quit app \"$1\""
}
So I wanted to use a find command in shell in my AppleScript. I wanted to search my entire disk for a certain filetype so I did something like this:
set theItems to do shell script "find / -name '*.mp3'" with administrator privileges
set theItems to paragraphs of theItems
repeat with theFile in theItems
--some code that process every file here
end repeat
The problem is that, even though I added the extra with administrator privileges, some files are still owned by the system and I don't have access to them. In my loop, I have some code in place that will deal with those lines though.
Is there a way to just ignore those?
Since the find command gets errors accessing some files/directories, it's going to report errors and exit with an error status; when do shell script sees that error, it throws an AppleScript-level error of its own.
You can make the script always succeed by adding || true to the end. In shell language, that means "if the find command fails (exits with error status), run true, which always succeeds, so the overall script succeeds.
I don't think it's necessary, but it might also be good to suppress the error messages that find prints by adding 2>/dev/null (although do shell script seems to ignore these messages as long as the overall command succeeds).
set theItems to do shell script "find / -name '*.mp3' 2>/dev/null || true" with administrator privileges
I do have a warning, however: this suppresses all errors from find, not just permissions errors, so if something else goes wrong you won't be notified.
I saw >_ in bash shell icon in mac and was wondering what it will do.
I tried performing the command but I was not able to figure out what happened. My command prompt silently came again.
It should be doing something, that's why it is in the icon for terminal.
Do anyone know what it does and can it be used for something?
Running >_ will successfully run (nothing), redirected to a file named _. It's not terribly useful, but that's what it does. The most useful empty redirection I've seen is to empty the contents of a file with it:
> /var/log/app.log
which, if app.log is not open by another process, will result in /var/log/app.log being empty.
When running putty commands through UFT i get a problem using type command. The "i" character causes to repeat some string after it sent.
Window("PuTTY").Type "cd /kenan/KNCBUST/data/Operation"
Window("PuTTY").Type micReturn
Above code returns following input at putty window
cknnzi21:/home/arbor : cd /kenan/KNCBUST/data/Operation/on
I changed to USA from control panel but it didnt solve anything.
Also same issue if i use Chr(105) instead of "i"
The problem was language of the OS and keyboard. If its set to English it can write commands without problem.
I've just started using Terminal (the CLI for Mac OS X).
When I run a command, get some information back, run another command, get more info etc., it is hard (on the eyes) to find a certain point on the screen (e.g. the output for the command before last).
Is there a way of adding a vertical empty space to the end of each output/ after each command is run that has no output?
Each new command that you enter is preceded by a "prompt", and these can be customized (though the exact way to customize depends on the shell). Since you mention Mac OS X I'm assuming you are using the default bash shell, in which case the absolute simplest way to add a blank line is like this: PROMPT_COMMAND=echo. You can run that command to try it out, or add it to a startup file (like .profile in your home folder) to have it done automatically each time.
If you use Bash 4.4 and you want a blank line after your prompt, you could set the PS0 prompt to a newline:
PS0="\n"
Now, this will be inserted every time you run a command:
$ echo "Hello"
Hello
Wondering this too, I've looked at the menu options in Terminal & most of the control characters one can type in and nothing does this on a keystroke. You can however enter an echo command, it alone to leave a single blank line below it before the next prompt. echo \n will add an extra blank line to that, echo \n\n to do 2 extra, ie. 3 blank lines, etc. (you can also do echo;echo;echo getting the same effect)
You can create a shell alias like alias b='echo;echo' (i couldn't seem to get the \n notation to work in a alias), then entering b on a prompt will leave a double-blank line, not bad. Then you gotta figure out how to save aliases in your .profile script.
I tried making an alias for the command ' ' ie. space character, which I though you could type like \ (hmm, stack overflow not formatting this well, that's backslash followed by a space, then return to execute it), but the bash shell doesn't seem to allow an alias with that name. It probably wouldn't allow a function named that either (similar to alias), though I didn't check.
I often use the fish shell, and I found that it does allow a function with that name! Created with function ' '; echo \n; end and indeed it works; at the shell prompt, typing the command \ (again backslash space) leaves a double blank line.
Cool, but.. I tried saving this function using funcsave ' ' (how you save functions in fish, no messing with startup scripts!) and afterwards the function no longer works :^( This is probably a bug in the fish shell. It's in active development right now though, I think I'll report this as a bug since I would kind of like this to work myself.
One could also send Apple a feature request through their bug reporter for an Insert Blank Line menu/keyboard command in Terminal. If someone pays attention to your request it might be implemented in a year maybe.
I wanted to solve exactly the same, and for anyone interested in doing the same, I used what tripleee said in his comment here - I created a .bash_profile (see details here) with the line export PS1="\n\n$ ".
Hopefully that helps someone else too!