How to get the current workspace programmatically on macOS
I would like to be able to tell at any time which mission control workspace the user is currently using programmatically on macOS 10.13.
I could not find any working answer during my search.
Any langage will do, and any workspace identifier works for me (uuid, workspace number...)
Thank you for the help!
macos cocoa applescript mission-control
add a comment |
I would like to be able to tell at any time which mission control workspace the user is currently using programmatically on macOS 10.13.
I could not find any working answer during my search.
Any langage will do, and any workspace identifier works for me (uuid, workspace number...)
Thank you for the help!
macos cocoa applescript mission-control
1
After I posted my "working answer" down below, I created for myself a "Menu Bar Icon" that consists of a simple .sh-script . . .#!/bin/bash _/¯ osascript /Users/myComputerName/.config/bitbar/Workingspace_Desktop.app
. . . simply placed in a 3rd party's ("BitBar") plugIns folder which calls an AppleScript that withif BGname is "Sierra.jpg" then set BGname to " [ 1 ] "
etc. displays [ 1 ] or [ 2 ] or [ 3 ] or [ 4 ] in my right-side menu bar. If you read so far you will guess that ANY message can thus be displayed permanently …
– clemsam lang
Nov 26 '18 at 15:53
add a comment |
I would like to be able to tell at any time which mission control workspace the user is currently using programmatically on macOS 10.13.
I could not find any working answer during my search.
Any langage will do, and any workspace identifier works for me (uuid, workspace number...)
Thank you for the help!
macos cocoa applescript mission-control
I would like to be able to tell at any time which mission control workspace the user is currently using programmatically on macOS 10.13.
I could not find any working answer during my search.
Any langage will do, and any workspace identifier works for me (uuid, workspace number...)
Thank you for the help!
macos cocoa applescript mission-control
macos cocoa applescript mission-control
asked Nov 3 '18 at 15:36
Louis MLouis M
1,20011118
1,20011118
1
After I posted my "working answer" down below, I created for myself a "Menu Bar Icon" that consists of a simple .sh-script . . .#!/bin/bash _/¯ osascript /Users/myComputerName/.config/bitbar/Workingspace_Desktop.app
. . . simply placed in a 3rd party's ("BitBar") plugIns folder which calls an AppleScript that withif BGname is "Sierra.jpg" then set BGname to " [ 1 ] "
etc. displays [ 1 ] or [ 2 ] or [ 3 ] or [ 4 ] in my right-side menu bar. If you read so far you will guess that ANY message can thus be displayed permanently …
– clemsam lang
Nov 26 '18 at 15:53
add a comment |
1
After I posted my "working answer" down below, I created for myself a "Menu Bar Icon" that consists of a simple .sh-script . . .#!/bin/bash _/¯ osascript /Users/myComputerName/.config/bitbar/Workingspace_Desktop.app
. . . simply placed in a 3rd party's ("BitBar") plugIns folder which calls an AppleScript that withif BGname is "Sierra.jpg" then set BGname to " [ 1 ] "
etc. displays [ 1 ] or [ 2 ] or [ 3 ] or [ 4 ] in my right-side menu bar. If you read so far you will guess that ANY message can thus be displayed permanently …
– clemsam lang
Nov 26 '18 at 15:53
1
1
After I posted my "working answer" down below, I created for myself a "Menu Bar Icon" that consists of a simple .sh-script . . .
#!/bin/bash _/¯ osascript /Users/myComputerName/.config/bitbar/Workingspace_Desktop.app
. . . simply placed in a 3rd party's ("BitBar") plugIns folder which calls an AppleScript that with if BGname is "Sierra.jpg" then set BGname to " [ 1 ] "
etc. displays [ 1 ] or [ 2 ] or [ 3 ] or [ 4 ] in my right-side menu bar. If you read so far you will guess that ANY message can thus be displayed permanently …– clemsam lang
Nov 26 '18 at 15:53
After I posted my "working answer" down below, I created for myself a "Menu Bar Icon" that consists of a simple .sh-script . . .
#!/bin/bash _/¯ osascript /Users/myComputerName/.config/bitbar/Workingspace_Desktop.app
. . . simply placed in a 3rd party's ("BitBar") plugIns folder which calls an AppleScript that with if BGname is "Sierra.jpg" then set BGname to " [ 1 ] "
etc. displays [ 1 ] or [ 2 ] or [ 3 ] or [ 4 ] in my right-side menu bar. If you read so far you will guess that ANY message can thus be displayed permanently …– clemsam lang
Nov 26 '18 at 15:53
add a comment |
3 Answers
3
active
oldest
votes
Looks like this requires undocumented API calls.
https://github.com/asmagill/hs._asm.undocumented.spaces/blob/master/CGSSpace.h
and
CG_EXTERN CGSSpaceID CGSGetActiveSpace(CGSConnectionID cid);
may do what you want, but this code hasn't been touched in 3 years so system/api may have migrated, and all the problems with using undocumented APIs apply.
Found this in the project https://github.com/asmagill/hs._asm.undocumented.spaces
haven't used or verified it.
add a comment |
- Download the private CGSInternal headers
- Put them in a folder on your system
- Go to your Projects
Build Settings
and add that folder toUser Header Search Paths
Then you can do this:
#import "AppDelegate.h"
#import "CGSInternal/CGSSpace.h"
@implementation AppDelegate
typedef int CGSConnection;
extern CGSConnection _CGSDefaultConnection(void);
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
CGSSpaceID activeSpace = CGSGetActiveSpace(_CGSDefaultConnection());
NSLog(@"activeSpace: %zu", activeSpace);
CFArrayRef spaceArray = CGSCopySpaces(_CGSDefaultConnection(), kCGSAllSpacesMask);
NSLog(@"allSpaces: %@", spaceArray);
}
@end
add a comment |
If you want a "working answer" use an indirect GUI "variable" to tell you where you are:
(<= shorter but politically in-correct)tell application "System Events" to text items 27 thru -1 of item 1 of (picture of every desktop as list) as string
set delimOrgs to text item delimiters
set text item delimiters to {"/"}
tell application "System Events" to set BGpict to ¬
last text item of (picture of current desktop as text)
set text item delimiters to delimOrgs
return BGpict [improved: user3439894's suggestion]
… which e.g. returns "Lion.jpg"
on one of my 4 workspaces, "Sierra.jpg"
on another, which means I was using desktop 3 first and desktop 1 right now.
Thanks, that's pragmatic!
– Louis M
Nov 21 '18 at 10:15
(What reason did ANYone have to vote DOWN this answer that actually helped someone – and was clearly marked as a "working solution" ?!? I DO not understand some "users" here ... "So sad" ;-) .)
– clemsam lang
Nov 22 '18 at 20:25
1
1. One should never changetext item delimiters
(you don't really need "AppleScript's
") without resetting them immediately after the non-default use. 2. The code,(picture of every desktop as list)
, only returns the picture of thecurrent desktop
, so why not just use it instead, e.g.last text item of (picture of current desktop as text)
. IMO It's the more proper way to do it when setting/
as the delimiter. 3. Your answer is not valid if each Desktop has the same wallpaper, so IMO it's not a good general solution since explicit conditions must exit for it to be worth anything.
– user3439894
Nov 23 '18 at 2:25
Also, if this type of code it run from a full screen app, which is in most cases a separate virtual Desktop, it's going to report the Wallpaper of the Desktop the app was launched full screen from and therefore doesn't actually return the real virtual Desktop position as shown in Mission Control, further making this answer rather limited in it's ability to accurately determine which space one is in at time of execution. Over all, not really a good answer and I can see why someone chose to downvote your original answer.
– user3439894
Nov 23 '18 at 2:25
I am deeply honoured by such a renowned user's critical DOUBLE comment. All he (or "she": I now try to be politically correct also in those details that really nobody cares a s**t for) criticises is worth considering, excepting his IMHO overly academic if not "unworldly" thought's on "full screen". I NEVER use apps in full screen mode, but even then the "right" desktop would be returned … for PRACTICAL purposes! His "explicit conditions" are actually the ones HE has MADE UP quite painstakingly if not superfluously. His critique to my solution will help NObody to better code ... Best regards,
– clemsam lang
Nov 23 '18 at 7:32
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53132824%2fhow-to-get-the-current-workspace-programmatically-on-macos%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Looks like this requires undocumented API calls.
https://github.com/asmagill/hs._asm.undocumented.spaces/blob/master/CGSSpace.h
and
CG_EXTERN CGSSpaceID CGSGetActiveSpace(CGSConnectionID cid);
may do what you want, but this code hasn't been touched in 3 years so system/api may have migrated, and all the problems with using undocumented APIs apply.
Found this in the project https://github.com/asmagill/hs._asm.undocumented.spaces
haven't used or verified it.
add a comment |
Looks like this requires undocumented API calls.
https://github.com/asmagill/hs._asm.undocumented.spaces/blob/master/CGSSpace.h
and
CG_EXTERN CGSSpaceID CGSGetActiveSpace(CGSConnectionID cid);
may do what you want, but this code hasn't been touched in 3 years so system/api may have migrated, and all the problems with using undocumented APIs apply.
Found this in the project https://github.com/asmagill/hs._asm.undocumented.spaces
haven't used or verified it.
add a comment |
Looks like this requires undocumented API calls.
https://github.com/asmagill/hs._asm.undocumented.spaces/blob/master/CGSSpace.h
and
CG_EXTERN CGSSpaceID CGSGetActiveSpace(CGSConnectionID cid);
may do what you want, but this code hasn't been touched in 3 years so system/api may have migrated, and all the problems with using undocumented APIs apply.
Found this in the project https://github.com/asmagill/hs._asm.undocumented.spaces
haven't used or verified it.
Looks like this requires undocumented API calls.
https://github.com/asmagill/hs._asm.undocumented.spaces/blob/master/CGSSpace.h
and
CG_EXTERN CGSSpaceID CGSGetActiveSpace(CGSConnectionID cid);
may do what you want, but this code hasn't been touched in 3 years so system/api may have migrated, and all the problems with using undocumented APIs apply.
Found this in the project https://github.com/asmagill/hs._asm.undocumented.spaces
haven't used or verified it.
answered Nov 3 '18 at 16:38
DadDad
4,40812028
4,40812028
add a comment |
add a comment |
- Download the private CGSInternal headers
- Put them in a folder on your system
- Go to your Projects
Build Settings
and add that folder toUser Header Search Paths
Then you can do this:
#import "AppDelegate.h"
#import "CGSInternal/CGSSpace.h"
@implementation AppDelegate
typedef int CGSConnection;
extern CGSConnection _CGSDefaultConnection(void);
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
CGSSpaceID activeSpace = CGSGetActiveSpace(_CGSDefaultConnection());
NSLog(@"activeSpace: %zu", activeSpace);
CFArrayRef spaceArray = CGSCopySpaces(_CGSDefaultConnection(), kCGSAllSpacesMask);
NSLog(@"allSpaces: %@", spaceArray);
}
@end
add a comment |
- Download the private CGSInternal headers
- Put them in a folder on your system
- Go to your Projects
Build Settings
and add that folder toUser Header Search Paths
Then you can do this:
#import "AppDelegate.h"
#import "CGSInternal/CGSSpace.h"
@implementation AppDelegate
typedef int CGSConnection;
extern CGSConnection _CGSDefaultConnection(void);
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
CGSSpaceID activeSpace = CGSGetActiveSpace(_CGSDefaultConnection());
NSLog(@"activeSpace: %zu", activeSpace);
CFArrayRef spaceArray = CGSCopySpaces(_CGSDefaultConnection(), kCGSAllSpacesMask);
NSLog(@"allSpaces: %@", spaceArray);
}
@end
add a comment |
- Download the private CGSInternal headers
- Put them in a folder on your system
- Go to your Projects
Build Settings
and add that folder toUser Header Search Paths
Then you can do this:
#import "AppDelegate.h"
#import "CGSInternal/CGSSpace.h"
@implementation AppDelegate
typedef int CGSConnection;
extern CGSConnection _CGSDefaultConnection(void);
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
CGSSpaceID activeSpace = CGSGetActiveSpace(_CGSDefaultConnection());
NSLog(@"activeSpace: %zu", activeSpace);
CFArrayRef spaceArray = CGSCopySpaces(_CGSDefaultConnection(), kCGSAllSpacesMask);
NSLog(@"allSpaces: %@", spaceArray);
}
@end
- Download the private CGSInternal headers
- Put them in a folder on your system
- Go to your Projects
Build Settings
and add that folder toUser Header Search Paths
Then you can do this:
#import "AppDelegate.h"
#import "CGSInternal/CGSSpace.h"
@implementation AppDelegate
typedef int CGSConnection;
extern CGSConnection _CGSDefaultConnection(void);
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
CGSSpaceID activeSpace = CGSGetActiveSpace(_CGSDefaultConnection());
NSLog(@"activeSpace: %zu", activeSpace);
CFArrayRef spaceArray = CGSCopySpaces(_CGSDefaultConnection(), kCGSAllSpacesMask);
NSLog(@"allSpaces: %@", spaceArray);
}
@end
answered Nov 18 '18 at 12:07
simsulasimsula
277
277
add a comment |
add a comment |
If you want a "working answer" use an indirect GUI "variable" to tell you where you are:
(<= shorter but politically in-correct)tell application "System Events" to text items 27 thru -1 of item 1 of (picture of every desktop as list) as string
set delimOrgs to text item delimiters
set text item delimiters to {"/"}
tell application "System Events" to set BGpict to ¬
last text item of (picture of current desktop as text)
set text item delimiters to delimOrgs
return BGpict [improved: user3439894's suggestion]
… which e.g. returns "Lion.jpg"
on one of my 4 workspaces, "Sierra.jpg"
on another, which means I was using desktop 3 first and desktop 1 right now.
Thanks, that's pragmatic!
– Louis M
Nov 21 '18 at 10:15
(What reason did ANYone have to vote DOWN this answer that actually helped someone – and was clearly marked as a "working solution" ?!? I DO not understand some "users" here ... "So sad" ;-) .)
– clemsam lang
Nov 22 '18 at 20:25
1
1. One should never changetext item delimiters
(you don't really need "AppleScript's
") without resetting them immediately after the non-default use. 2. The code,(picture of every desktop as list)
, only returns the picture of thecurrent desktop
, so why not just use it instead, e.g.last text item of (picture of current desktop as text)
. IMO It's the more proper way to do it when setting/
as the delimiter. 3. Your answer is not valid if each Desktop has the same wallpaper, so IMO it's not a good general solution since explicit conditions must exit for it to be worth anything.
– user3439894
Nov 23 '18 at 2:25
Also, if this type of code it run from a full screen app, which is in most cases a separate virtual Desktop, it's going to report the Wallpaper of the Desktop the app was launched full screen from and therefore doesn't actually return the real virtual Desktop position as shown in Mission Control, further making this answer rather limited in it's ability to accurately determine which space one is in at time of execution. Over all, not really a good answer and I can see why someone chose to downvote your original answer.
– user3439894
Nov 23 '18 at 2:25
I am deeply honoured by such a renowned user's critical DOUBLE comment. All he (or "she": I now try to be politically correct also in those details that really nobody cares a s**t for) criticises is worth considering, excepting his IMHO overly academic if not "unworldly" thought's on "full screen". I NEVER use apps in full screen mode, but even then the "right" desktop would be returned … for PRACTICAL purposes! His "explicit conditions" are actually the ones HE has MADE UP quite painstakingly if not superfluously. His critique to my solution will help NObody to better code ... Best regards,
– clemsam lang
Nov 23 '18 at 7:32
|
show 3 more comments
If you want a "working answer" use an indirect GUI "variable" to tell you where you are:
(<= shorter but politically in-correct)tell application "System Events" to text items 27 thru -1 of item 1 of (picture of every desktop as list) as string
set delimOrgs to text item delimiters
set text item delimiters to {"/"}
tell application "System Events" to set BGpict to ¬
last text item of (picture of current desktop as text)
set text item delimiters to delimOrgs
return BGpict [improved: user3439894's suggestion]
… which e.g. returns "Lion.jpg"
on one of my 4 workspaces, "Sierra.jpg"
on another, which means I was using desktop 3 first and desktop 1 right now.
Thanks, that's pragmatic!
– Louis M
Nov 21 '18 at 10:15
(What reason did ANYone have to vote DOWN this answer that actually helped someone – and was clearly marked as a "working solution" ?!? I DO not understand some "users" here ... "So sad" ;-) .)
– clemsam lang
Nov 22 '18 at 20:25
1
1. One should never changetext item delimiters
(you don't really need "AppleScript's
") without resetting them immediately after the non-default use. 2. The code,(picture of every desktop as list)
, only returns the picture of thecurrent desktop
, so why not just use it instead, e.g.last text item of (picture of current desktop as text)
. IMO It's the more proper way to do it when setting/
as the delimiter. 3. Your answer is not valid if each Desktop has the same wallpaper, so IMO it's not a good general solution since explicit conditions must exit for it to be worth anything.
– user3439894
Nov 23 '18 at 2:25
Also, if this type of code it run from a full screen app, which is in most cases a separate virtual Desktop, it's going to report the Wallpaper of the Desktop the app was launched full screen from and therefore doesn't actually return the real virtual Desktop position as shown in Mission Control, further making this answer rather limited in it's ability to accurately determine which space one is in at time of execution. Over all, not really a good answer and I can see why someone chose to downvote your original answer.
– user3439894
Nov 23 '18 at 2:25
I am deeply honoured by such a renowned user's critical DOUBLE comment. All he (or "she": I now try to be politically correct also in those details that really nobody cares a s**t for) criticises is worth considering, excepting his IMHO overly academic if not "unworldly" thought's on "full screen". I NEVER use apps in full screen mode, but even then the "right" desktop would be returned … for PRACTICAL purposes! His "explicit conditions" are actually the ones HE has MADE UP quite painstakingly if not superfluously. His critique to my solution will help NObody to better code ... Best regards,
– clemsam lang
Nov 23 '18 at 7:32
|
show 3 more comments
If you want a "working answer" use an indirect GUI "variable" to tell you where you are:
(<= shorter but politically in-correct)tell application "System Events" to text items 27 thru -1 of item 1 of (picture of every desktop as list) as string
set delimOrgs to text item delimiters
set text item delimiters to {"/"}
tell application "System Events" to set BGpict to ¬
last text item of (picture of current desktop as text)
set text item delimiters to delimOrgs
return BGpict [improved: user3439894's suggestion]
… which e.g. returns "Lion.jpg"
on one of my 4 workspaces, "Sierra.jpg"
on another, which means I was using desktop 3 first and desktop 1 right now.
If you want a "working answer" use an indirect GUI "variable" to tell you where you are:
(<= shorter but politically in-correct)tell application "System Events" to text items 27 thru -1 of item 1 of (picture of every desktop as list) as string
set delimOrgs to text item delimiters
set text item delimiters to {"/"}
tell application "System Events" to set BGpict to ¬
last text item of (picture of current desktop as text)
set text item delimiters to delimOrgs
return BGpict [improved: user3439894's suggestion]
… which e.g. returns "Lion.jpg"
on one of my 4 workspaces, "Sierra.jpg"
on another, which means I was using desktop 3 first and desktop 1 right now.
edited Nov 24 '18 at 19:20
answered Nov 20 '18 at 15:39
clemsam langclemsam lang
23819
23819
Thanks, that's pragmatic!
– Louis M
Nov 21 '18 at 10:15
(What reason did ANYone have to vote DOWN this answer that actually helped someone – and was clearly marked as a "working solution" ?!? I DO not understand some "users" here ... "So sad" ;-) .)
– clemsam lang
Nov 22 '18 at 20:25
1
1. One should never changetext item delimiters
(you don't really need "AppleScript's
") without resetting them immediately after the non-default use. 2. The code,(picture of every desktop as list)
, only returns the picture of thecurrent desktop
, so why not just use it instead, e.g.last text item of (picture of current desktop as text)
. IMO It's the more proper way to do it when setting/
as the delimiter. 3. Your answer is not valid if each Desktop has the same wallpaper, so IMO it's not a good general solution since explicit conditions must exit for it to be worth anything.
– user3439894
Nov 23 '18 at 2:25
Also, if this type of code it run from a full screen app, which is in most cases a separate virtual Desktop, it's going to report the Wallpaper of the Desktop the app was launched full screen from and therefore doesn't actually return the real virtual Desktop position as shown in Mission Control, further making this answer rather limited in it's ability to accurately determine which space one is in at time of execution. Over all, not really a good answer and I can see why someone chose to downvote your original answer.
– user3439894
Nov 23 '18 at 2:25
I am deeply honoured by such a renowned user's critical DOUBLE comment. All he (or "she": I now try to be politically correct also in those details that really nobody cares a s**t for) criticises is worth considering, excepting his IMHO overly academic if not "unworldly" thought's on "full screen". I NEVER use apps in full screen mode, but even then the "right" desktop would be returned … for PRACTICAL purposes! His "explicit conditions" are actually the ones HE has MADE UP quite painstakingly if not superfluously. His critique to my solution will help NObody to better code ... Best regards,
– clemsam lang
Nov 23 '18 at 7:32
|
show 3 more comments
Thanks, that's pragmatic!
– Louis M
Nov 21 '18 at 10:15
(What reason did ANYone have to vote DOWN this answer that actually helped someone – and was clearly marked as a "working solution" ?!? I DO not understand some "users" here ... "So sad" ;-) .)
– clemsam lang
Nov 22 '18 at 20:25
1
1. One should never changetext item delimiters
(you don't really need "AppleScript's
") without resetting them immediately after the non-default use. 2. The code,(picture of every desktop as list)
, only returns the picture of thecurrent desktop
, so why not just use it instead, e.g.last text item of (picture of current desktop as text)
. IMO It's the more proper way to do it when setting/
as the delimiter. 3. Your answer is not valid if each Desktop has the same wallpaper, so IMO it's not a good general solution since explicit conditions must exit for it to be worth anything.
– user3439894
Nov 23 '18 at 2:25
Also, if this type of code it run from a full screen app, which is in most cases a separate virtual Desktop, it's going to report the Wallpaper of the Desktop the app was launched full screen from and therefore doesn't actually return the real virtual Desktop position as shown in Mission Control, further making this answer rather limited in it's ability to accurately determine which space one is in at time of execution. Over all, not really a good answer and I can see why someone chose to downvote your original answer.
– user3439894
Nov 23 '18 at 2:25
I am deeply honoured by such a renowned user's critical DOUBLE comment. All he (or "she": I now try to be politically correct also in those details that really nobody cares a s**t for) criticises is worth considering, excepting his IMHO overly academic if not "unworldly" thought's on "full screen". I NEVER use apps in full screen mode, but even then the "right" desktop would be returned … for PRACTICAL purposes! His "explicit conditions" are actually the ones HE has MADE UP quite painstakingly if not superfluously. His critique to my solution will help NObody to better code ... Best regards,
– clemsam lang
Nov 23 '18 at 7:32
Thanks, that's pragmatic!
– Louis M
Nov 21 '18 at 10:15
Thanks, that's pragmatic!
– Louis M
Nov 21 '18 at 10:15
(What reason did ANYone have to vote DOWN this answer that actually helped someone – and was clearly marked as a "working solution" ?!? I DO not understand some "users" here ... "So sad" ;-) .)
– clemsam lang
Nov 22 '18 at 20:25
(What reason did ANYone have to vote DOWN this answer that actually helped someone – and was clearly marked as a "working solution" ?!? I DO not understand some "users" here ... "So sad" ;-) .)
– clemsam lang
Nov 22 '18 at 20:25
1
1
1. One should never change
text item delimiters
(you don't really need "AppleScript's
") without resetting them immediately after the non-default use. 2. The code, (picture of every desktop as list)
, only returns the picture of the current desktop
, so why not just use it instead, e.g. last text item of (picture of current desktop as text)
. IMO It's the more proper way to do it when setting /
as the delimiter. 3. Your answer is not valid if each Desktop has the same wallpaper, so IMO it's not a good general solution since explicit conditions must exit for it to be worth anything.– user3439894
Nov 23 '18 at 2:25
1. One should never change
text item delimiters
(you don't really need "AppleScript's
") without resetting them immediately after the non-default use. 2. The code, (picture of every desktop as list)
, only returns the picture of the current desktop
, so why not just use it instead, e.g. last text item of (picture of current desktop as text)
. IMO It's the more proper way to do it when setting /
as the delimiter. 3. Your answer is not valid if each Desktop has the same wallpaper, so IMO it's not a good general solution since explicit conditions must exit for it to be worth anything.– user3439894
Nov 23 '18 at 2:25
Also, if this type of code it run from a full screen app, which is in most cases a separate virtual Desktop, it's going to report the Wallpaper of the Desktop the app was launched full screen from and therefore doesn't actually return the real virtual Desktop position as shown in Mission Control, further making this answer rather limited in it's ability to accurately determine which space one is in at time of execution. Over all, not really a good answer and I can see why someone chose to downvote your original answer.
– user3439894
Nov 23 '18 at 2:25
Also, if this type of code it run from a full screen app, which is in most cases a separate virtual Desktop, it's going to report the Wallpaper of the Desktop the app was launched full screen from and therefore doesn't actually return the real virtual Desktop position as shown in Mission Control, further making this answer rather limited in it's ability to accurately determine which space one is in at time of execution. Over all, not really a good answer and I can see why someone chose to downvote your original answer.
– user3439894
Nov 23 '18 at 2:25
I am deeply honoured by such a renowned user's critical DOUBLE comment. All he (or "she": I now try to be politically correct also in those details that really nobody cares a s**t for) criticises is worth considering, excepting his IMHO overly academic if not "unworldly" thought's on "full screen". I NEVER use apps in full screen mode, but even then the "right" desktop would be returned … for PRACTICAL purposes! His "explicit conditions" are actually the ones HE has MADE UP quite painstakingly if not superfluously. His critique to my solution will help NObody to better code ... Best regards,
– clemsam lang
Nov 23 '18 at 7:32
I am deeply honoured by such a renowned user's critical DOUBLE comment. All he (or "she": I now try to be politically correct also in those details that really nobody cares a s**t for) criticises is worth considering, excepting his IMHO overly academic if not "unworldly" thought's on "full screen". I NEVER use apps in full screen mode, but even then the "right" desktop would be returned … for PRACTICAL purposes! His "explicit conditions" are actually the ones HE has MADE UP quite painstakingly if not superfluously. His critique to my solution will help NObody to better code ... Best regards,
– clemsam lang
Nov 23 '18 at 7:32
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53132824%2fhow-to-get-the-current-workspace-programmatically-on-macos%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
After I posted my "working answer" down below, I created for myself a "Menu Bar Icon" that consists of a simple .sh-script . . .
#!/bin/bash _/¯ osascript /Users/myComputerName/.config/bitbar/Workingspace_Desktop.app
. . . simply placed in a 3rd party's ("BitBar") plugIns folder which calls an AppleScript that withif BGname is "Sierra.jpg" then set BGname to " [ 1 ] "
etc. displays [ 1 ] or [ 2 ] or [ 3 ] or [ 4 ] in my right-side menu bar. If you read so far you will guess that ANY message can thus be displayed permanently …– clemsam lang
Nov 26 '18 at 15:53