How can I programmatically add a space to mission control? - macos

I want to create a new space (and also be able to delete it later), without having to go through the standard misson control gui. Is there any way to do this programmatically? Either via terminal commands, applescript or some cocoa?

From the GUI...
...just in case someone finds this via Google
It’s a cinch: when you’re in Mission Control...
move your cursor to the upper right corner of the screen
click the New Desktop tab that slides out from the edge of the screen
Note:If your Dock is on the right, you can access the New Desktop tab from the upper left corner instead.
In Mavericks, Applescript to create a new Space in Mission Control
delay 0.5 -- time to release command if the script is run with command-R
tell application "System Events"
key code 126 using control down -- control-up
delay 1
do shell script "MouseTools -x 1900 -y 60;sleep 1;MouseTools -leftClickNoRelease;MouseTools -releaseMouse"
key code 53 -- escape
end tell

There is on preference plist in ~/Library/Preferences path named as com.apple.spaces.plist.
There You have to add two keys.
Open the plist and I hope you will get to know it.

Related

(NO mystery:) How Automator transfers "invisible" information to Script-Editor

( I have been pushed to an obvious answer to my "Mystery" from a friendly member here.
I feel a little ashamed not to have found this solution myself, but will leave this posting online if there aren't too many irritated folks around. Maybe someone else can learn from this … apologies to every "know-it-alls"!)
I have recorded these actions with Automator:
– Cmd-tab to bring TextEdit to front (must have some lines typed)
– Pressed left arrow 7 times using shift down
– Stopped the recording
Next I selected and copied (Cmd-c) all action icons in Automator's "Record my actions" window.
I switched to Script-Editor and pasted (Cmd-v) them into a new window.
Then, I repeated above recording with 3 times UP arrow and copied icons into another new window.
I took only the two "set uiScript to …" lines and appended them in the first script.
THEY READ IDENTICAL:
set uiScript to "keystroke \"\t\" using command down"
my doWithTimeout(uiScript)
set uiScript to "keystroke \"\" using shift down" -- 7 times left-arrow
my doWithTimeout(uiScript)
set uiScript to "keystroke \"\" using shift down" -- 3 times up-arrow
my doWithTimeout(uiScript)
on doWithTimeout(uiScript)
set endDate to (current date)
repeat
try
run script "tell application \"System Events\"\n" & uiScript & "\nend tell"
exit repeat
end try
end repeat
end doWithTimeout
(To make resulting code more readable I omitted error code and "delays".)
Now, if I disable one of the "keystroke" lines (=> --my doWith…) the script somehow knows that it either has to do Shift-leftArrow 7 times OR Shift-upArrow 3 times.
I tried this after computer restart, even copied the code from this web page and pasted it into a new Script Editor window – it still knew what to do!
HOW CAN THAT BE ???
My only idea is: there must be some internal Applescript database that recognises content even if copied/pasted.
Does anybody know ?
Only if I re-write the code identically will there happen NOTHING – until I copy the first line of either recording ("set uiScript to …"). So the information must be linked to this first line somehow.
(BTW: first two lines that bring TextEdit –or, e.g. a Finder window– to the front work only from opened Script Editor; you have to bring TextEdit to the front yourself, if you start the saved-as-program script from Script-Editor's menu icon subfolder. Nevertheless the script won't work without them…)
It "knows" because the keystrokes are in the string - keystrokes using control type keys (such as arrow keys) just don’t have a text representation, so they wind up being invisible. Some text editors such as BBEdit can show these invisible characters, but they don’t show up in the Script Editor.
Apple has obviously made Automator's Watch Me Do action able to capture some of these control keys in a string, but for the rest of us it is more difficult, since the control keys will actually perform their function when pressed. If you need to use these kinds of keys, the key code command can be used, since it refers to the actual keyboard key, for example:
tell application "System Events"
repeat 3 times
key code 126 using shift down -- up arrow
end repeat
end tell
As the answer is quite simple but may still be interesting to some, I'll explain it shortly:
red_menace (in his comment above) pointed out that strings may contain invisible elements (like arrow keys), therefore I next checked the obvious:
If you "cursor-walk" along the "set uiScript …" strings the cursor will actually "pause" for 7 or 3 "steps" respectively on its way.
I hadn't thought/heard of any "invisible" string-chars (apart from obvious ones in Word etc.).

Run AppleScript progress bar in separate window from command line?

To display dialogs from the command line I just use
$ osascript File.scpt
However, the progress bar feature isn't constrained to a dialog window because it adapts to the current application, e.g. a Finder window, where the progress updates are shown on the bottom of the window. File.scpt would look something like this.
set numUpdates to 100
set progress total steps to numUpdates
set progress completed steps to 0
set progress description to "Updating..."
set progress additional description to "Preparing to process."
set cycle to 1
repeat with a from 1 to numUpdates
# update description, completed steps, etc
end repeat
When I run my script from a terminal window, however, the script runs but nothing is shown to indicate the progress. Is there a way to force the progress bar to open as a new dialog or something along those lines without having to export the script as a ".app" file?
The reason Script Editor can display progress in its window and Terminal cannot is because Script Editor has its own extended scripting definition with the extra functions so when the script is run via script editor it has been programmed with the extra progress indicator but no other applications are sorry. The way I see it, you pretty much have 2 ways I can think of that will let you display "Progress" in AppleScript:
This is kinda ugly but I used to just have a transparent spinner gif file that will be displayed in a dialog which will give the affect that something is loading or working. and a single button saying Nothing or OK eg.
display dialog "Loading..." buttons:{"OK"} with icon ("/path/to/loader.gif" as POSIX file)
And if you wanna make it temporary just add giving up after (duration in seconds)
This is probably the best option but it is probably more complicated. I advise that you transfer to a programming language called "AppleScript Objective C" otherwise known as "Cocoa AppleScript". This allows you to use the basic AppleScript commands with Cocoa Windows/Dialogs/etc including progress bars!. to start you off you should download Xcode and research AppleScript Objective C and perhaps stick to it. Its better than AppleScript but still has the same functions :)

Mac OS X Specify Keyboard Shortcut

How can i set the keyboard in Mac OS X Yosemite so i can map the function keys to write specified symbols?
I want to be able to write \( every time press F1
use Automator!
Open Automator (search for it in spotlight) and click the new document button
select service as the type of document
on the top left, there is a search bar in Automator. Simply search for run
one of the resulting options is Run AppleScript
Drag this onto the main part of the window, it will add a skeleton script
under where it says (*Your script goes here *), type this:
tell application "System Events"
keystroke "\\("
end tell
the two slashes are needed to produce one slash!
Now save this, the default location is fine!
Next, go into settings. open the keyboard icon
under the shortcuts tab, choose in the left pane, Services
Scroll to the bottom and your script should appear! select it and Double click where it says add shortcut. Now input your short cut. make sure there is no other shortcut assigned to that key
Now I must admit, I didn't get f1 to work in some apps because they had override shortcuts for F1. For example, the settings search bar printed ( when I hit F1 but in notes it didn't. If you have a keyboeard, you should probably try an F key greater than 12
Hope this works!

Type a pre defined text when a shortcut key is pressed in Windows 7

I work on mainframes and don't have much knowledge about windows other than playing warcraft :-) hence pardon me if I ask something nooby/silly.
I have a requirement to enter a particular long-text in the current position of a cursor whenever a shortcut key is pressed.
I am thinking of creating a bat file and assigning a windows keyboard shortcut to the bat file and whenever I have requirement to enter the long text, I press the windows shortcut key
and the long text gets typed in the current position of the cursor.
The current position of the cursor can be in any application, like Excel, Word or notepad or Windows dialog prompts.
Could you please let me know if this is possible and point me where I could get some information about this "technique".
Thanks & Regards,
Vasanth.S
To make a single key combo do what you are asking, you may need another program. You can make a link to a batch file, hook up a shortcut and then use the clip command to copy text from a file onto the clipboard. That would require the shortcut and then a Ctrl+V to paste. The batch file would look like this:
clip < c:\SomeDir\sometext.txt
You might like to look at using a clipboard manager - which saves a history of clipboard entries, can search for an entry, and paste it at the cursor.
Ditto and CLCL are both useful and free - which one you use depends on your windows version.
They are hotkey driven for ease of use, but mouse can be used.

How to maximize command prompt in windows xp

I am on windows xp,
Is there any way to maximize my cmd.exe window?
I am doing some mysql and it is so difficult to read results of my queries in such a small window.
Why maximize does not really maximizes it?
Is there a way for maximizing?
Or maybe an alternative command prompt I can use?
thanks
Click on the top left icon in the window (the "C:\" one) and select "Properties".
Then select the "Layout" tab and change the window size to what you want it to be (I have 128x50 for the screen and 128x999 for the scroll buffer). You can also optionally set the top left position (I always have it at 1,1) if you don't want Windows itself deciding where the window goes.
When you click on OK, make sure you tell it to modify the shortcut that started the window.
Then it will remember.
This is for XP, other MS operating systems may vary slightly but the general idea should be the same.
Try this:
In the Command window, right click the Title
bar and select Properties from the
popup menu. The property sheet
appears.
In the property sheet, select 'Full
Screen' in the 'Display Options'
box.
Close the property sheet by clicking
OK and select 'Save proeprties for
future windows with same title'.
I would recommand that you use powershell
http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx
It also support full screen mode, and some other nice feature.
Command Window Default Properties
Click on the sytem menu, or with focus set on the Command Windows, press Alt+Space, and select Properties. Change your Font, Window Size, and so on. I always change my Window Size (on the Layout tab) to Width 80 by Height 65 and Screen Buffer Size to 80 by 300.
Check out Console2, it seems to be about the most promising window enhancement for cmd.exe.
I have to say, cmd.exe is probably the worst part of windows! Especially the copy pasting support, etc.
Personally, I use putty to ssh into a Linux box when I really need to do command line work, you can't go past Bash.
Even though you could install that on windows using Cygwin, which will allow you to use another console, although this doesn't have the ability to override the windows cmd.exe, it might be worth a shot given that you are trying to use a command line application, and not windows :).
Access Properties by right clicking on top of the CMD window, go back to the Font tab, select either 10 x 18 or 12 x 16, and then click OK. You'll then need to go back to the Layout tab and reset the Screen Buffer Size Width to the appropriate value. For example, I selected the 10 x 18 font size and then changed the Screen Buffer Size Width to 160X300 and window size width to 134X37.

Resources