I'm trying to figure out how to programatically add a folder to Finder's Places sidebar. I've seen ways to modify it through the Finder Preferences, but I've also seen some applications actually add folders to the sidebar.
If someone has any advice/pointers on what I should look up, it would be greatly appreciated
(This is for Snow Leopard and Leopard... hopefully it didn't change)
Try this:
-(void) addPathToSharedItem:(NSString *)path
{
CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:path];
// Create a reference to the shared file list.
LSSharedFileListRef favoriteItems = LSSharedFileListCreate(NULL,
kLSSharedFileListFavoriteItems, NULL);
if (favoriteItems) {
//Insert an item to the list.
LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(favoriteItems,
kLSSharedFileListItemLast, NULL, NULL,
url, NULL, NULL);
if (item){
CFRelease(item);
}
}
CFRelease(favoriteItems);
}
Related
I'm using GTK+3 and I would like to do a recent-files submenu which it could update programmatically, not just by the GUI user interaction (that is working). I've used GtkRecentChooserMenu.
I've made this for setting the submenu:
GtkWidget * recentChooser = gtk_recent_chooser_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (win->menuItemRecent), recentChooser); //win->menuItemRecent is a GtkMenuItem
gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (recentChooser), TRUE);
GtkRecentFilter *filter = gtk_recent_filter_new ();
gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recentChooser), GTK_RECENT_SORT_MRU);
gtk_recent_filter_add_pattern (filter, "*.tnt");
gtk_recent_filter_add_pattern (filter, "*.run");
gtk_recent_filter_add_pattern (filter, "*.tre");
gtk_recent_filter_add_pattern (filter, "*.dat");
gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (recentChooser), filter);
g_signal_connect (G_OBJECT (recentChooser), "item-activated", G_CALLBACK (on_recentFile_activated), NULL);
gtk_recent_chooser_set_show_icons(GTK_RECENT_CHOOSER (recentChooser), FALSE);
As I said, all this is working. Now, for the programmatic submenu update, I've tried this:
submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM(win->menuItemRecent));
GtkRecentChooser * chooser = GTK_RECENT_CHOOSER(submenu);
GtkRecentManager * manager = GTK_RECENT_CHOOSER_GET_IFACE(chooser)->get_recent_manager (chooser);
gtk_recent_manager_add_item(manager, file); //file is a file name to add into submenu
But this isn't working. The gtk_recent_manager_add_item() seems add (because it returns TRUE) but the submenu doesn't update.
Thanks in advance.
Martín
I'm using Action Sheet Popup of the library Rg.Plugins.Popup on Xamarin Forms.
I want to display the image as below:
How to add an icon to Action Sheet Popup on Xamarin forms?
This is my code:
public Task<string> ShowActionSheetDialogAsync(string title, string cancelString = null, string destructive = null, CancellationToken? token = null, string[] arrayButtons = null)
{
return UserDialogs.Instance.ActionSheetAsync(title, cancelString,destructive, cancelToken: token,buttons:arrayButtons);
}
Or you can suggest another idea which might also show.
Please help me!
Use aritchie/userdialogs instead, it provides icon option for the item in list , check API .
Usage
IUserDialogs d = UserDialogs.Instance;
ActionSheetConfig config = new ActionSheetConfig();
List<ActionSheetOption> Options = new List<ActionSheetOption>();
Options.Add(new ActionSheetOption("1" , null , "info.png"));
Options.Add(new ActionSheetOption("2", null, "info.png"));
ActionSheetOption cancel = new ActionSheetOption("Cancel",null,null);
config.Options = Options;
config.Cancel = cancel;
d.ActionSheet(config);
Screen shot
This is platform-specific, so wrap it in DependencyService for example.
This is how you add image to an ActionSheet action:
UIImage img; //the image
var action = new UIAlertAction();
action.SetValueForKey("image", img);
Then add this UIAlertAction to a UIActionSheet. (You should also set Title and Action, of course)
Much like Safari, trying to implement a button that when clicked opens System Preferences > Extensions > Share Menu pane.
I have tried:
NSURL *URL = [NSURL URLWithString:#"x-apple.systempreferences:com.apple.preferences.extensions?Share_Menu"];
[[NSWorkspace sharedWorkspace] openURL:URL];
However it seems like that is not working on newer versions, any ideas?
You can use Scripting Bridge to do something like this:
SBSystemPreferencesApplication *systemPrefs =
[SBApplication applicationWithBundleIdentifier:#"com.apple.systempreferences"];
[systemPrefs activate];
SBElementArray *panes = [systemPrefs panes];
SBSystemPreferencesPane *notificationsPane = nil;
for (SBSystemPreferencesPane *pane in panes) {
if ([[pane id] isEqualToString:#"com.apple.preferences.extensions"]) {
notificationsPane = pane;
break;
}
}
[systemPrefs setCurrentPane:notificationsPane];
SBElementArray *anchors = [notificationsPane anchors];
for (SBSystemPreferencesAnchor *anchor in anchors) {
if ([anchor.name isEqualToString:#"Extensions"]) {
[anchor reveal];
}
}
Of course you need to add the ScriptingBridge framework to your project and a Scripting Bridge header file for system preferences. More details on how to use Scripting Bridge you can find in the developer documentation from Apple.
Hope this helps
Since macOS Ventura (13.0) you can call the URL
x-apple.systempreferences:com.apple.preferences.extensions?Sharing
I'm trying to add a THEME feature in my app protector application but i faced a big problem.
I can get layout from other application but the layout doesn't present the drawable
(ex. Background, Src, ...)
(ex. If i make a theme app with a layout whose background is "background.png", a main app can get a layout of the theme app but with no background!!)
↓↓Code
Resources theme = null;
try
{
theme = getPackageManager().getResourcesForApplication(nowTheme);
//nowTheme = packageName
}
catch (PackageManager.NameNotFoundException e)
{
}
if (theme != null)
{
int resID = theme.getIdentifier("theme" , "layout", nowTheme);
mView = mInflater.inflate(theme.getLayout(resID), null);
}
else
{
mView = mInflater.inflate(R.layout.theme_default, null);
dataConverter.dataPut(this, "default", SP_LOCATION_THEME, "theme");
//dataConverter = sharedpreferences
Toast.makeText(getApplicationContext(), "Error", 3000).show();
}
Is there any wrong code i do? :(
p.s I think that's because of "R.drawable" for background of the theme app
If you want the background appears, the layout must declare the background drawable resource in there. Check the layout or post the layout of your theme here.
I'm developing a cocoa application for Mac. I'm applying overlay icons on files and folders using my application. But my problem is that when I change icon for file or folder from my Application than its not reflecting it in the Finder unless I click on any file or folder in the Finder. For refreshing Finder I'm running following applescript using following code from my Application:
NSString *source=[NSString stringWithFormat:#"tell application \"Finder\" to update POSIX file \"%#\"",itemPath];
NSAppleScript *run = [[NSAppleScript alloc] initWithSource:source];
[run executeAndReturnError:nil];
But this code is not refreshing my Finder. Any idea how to refresh Finder to immediately reflect icon for file or folder??? Thanks in advance...
You must specify the class (folder, file, disk, item, ...) when you use a string in the Finder, item will work for all (folder, file, ...).
Without it, It works for some, but it is not the case for everyone
Also, "posix file thePath" in the Finder is more reliable with parentheses.
Try this
NSString *source=[NSString stringWithFormat:#"tell application \"Finder\" to update item (POSIX file \"%#\")",itemPath];
Or without NSApplescript :
[[NSWorkspace sharedWorkspace] noteFileSystemChanged: itemPath];
#"tell application \"Finder\" to update POSIX file \"%#\"" this script working fine for me.
You can also use apple events.
Below code is written by JWWalker
OSStatus SendFinderSyncEvent( const FSRef* inObjectRef )
{
AppleEvent theEvent = { typeNull, NULL };
AppleEvent replyEvent = { typeNull, NULL };
AliasHandle itemAlias = NULL;
const OSType kFinderSig = 'MACS';
OSStatus err = FSNewAliasMinimal( inObjectRef, &itemAlias );
if (err == noErr)
{
err = AEBuildAppleEvent( kAEFinderSuite, kAESync, typeApplSignature,
&kFinderSig, sizeof(OSType), kAutoGenerateReturnID,
kAnyTransactionID, &theEvent, NULL, "'----':alis(##)", itemAlias );
if (err == noErr)
{
err = AESendMessage( &theEvent, &replyEvent, kAENoReply,
kAEDefaultTimeout );
AEDisposeDesc( &replyEvent );
AEDisposeDesc( &theEvent );
}
DisposeHandle( (Handle)itemAlias );
}
return err;
}
Here's how I "refresh the Finder" when needed. Maybe it will help you ;)
tell application "Finder"
tell window 1 to update items
end tell
What worked for me is to 'touch' the file which updates the file modification date and thus triggers thumbnail icon refresh by the Finder.
NSString* path = "/Users/xx/...path_to_file"
NSString* command = [NSString stringWithFormat:#"touch \"%#\"", path];
int res = system(command.UTF8String);