-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDesktopImage.m
73 lines (62 loc) · 1.86 KB
/
DesktopImage.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// DesktopImage.m
// Toucan
//
// Created by will on 17/03/10.
// Copyright 2010 ExoApps. All rights reserved.
//
#import "DesktopImage.h"
@implementation DesktopImage
@synthesize imagePath;
- (void)dealloc
{
self.imagePath = nil;
[super dealloc];
}
- (void)changeDesktopImage
{
// SInt32 MacVersion;
//
// if (Gestalt(gestaltSystemVersion, &MacVersion) == noErr)
// {
// if(MacVersion < 0x1060)
// {
// //10.5 Framework
// NSString * script = [NSString stringWithFormat:
// @"tell application \"Finder\"\n"
// "set image_file to POSIX file \"%@\"\n"
// "set desktop picture to image_file\n"
// "end tell",
// self.imagePath];
//
// NSDictionary * anError = nil;
// NSAppleScript * aps = [[NSAppleScript alloc] initWithSource: script];
// [aps executeAndReturnError: &anError];
// [aps release];
//
// [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"com.apple.desktop" object: @"BackgroundChanged"];
// }
// else
// {
// //10.6 Framework
// NSError * error = nil;
// NSScreen * screen = [NSScreen mainScreen];
// NSURL * path = [NSURL fileURLWithPath: self.imagePath];
// [[NSWorkspace sharedWorkspace] setDesktopImageURL: path forScreen: screen options: nil error: &error];
// }
// }
// OS version =< 10.6.x
if([self.imagePath isEqualToString: @""]) return;
NSString * script = [NSString stringWithFormat:
@"tell application \"Finder\"\n"
"set image_file to POSIX file \"%@\"\n"
"set desktop picture to image_file\n"
"end tell",
self.imagePath];
NSDictionary * anError = nil;
NSAppleScript * aps = [[NSAppleScript alloc] initWithSource: script];
[aps executeAndReturnError: &anError];
[aps release];
[[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"com.apple.desktop" object: @"BackgroundChanged"];
}
@end