Skip to content

Commit

Permalink
Adds simple command line parsing to create a TmpDisk on startup from …
Browse files Browse the repository at this point in the history
…terminal.
  • Loading branch information
imothee committed Jul 1, 2012
1 parent 1bebd8c commit 21da40d
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 3 deletions.
8 changes: 7 additions & 1 deletion README.md
Expand Up @@ -17,4 +17,10 @@ Either install the dmg at http://inkscribbles.com/app/tmpdisk or clone the repos
Usage
-----

TmpDisk installs as a Status Bar application. You can use the menu to create new tmpdisks, eject existing tmpdisks and click on a disk to open it in finder.
TmpDisk installs as a Status Bar application. You can use the menu to create new tmpdisks, eject existing tmpdisks and click on a disk to open it in finder.

As of 1.0.4 you can also run the app from the command line and pass in arguments to create a TmpDisk on startup.

`open -a /Applications/TmpDisk.app --args -name=TestDisk -size=64`

Will create a TmpDisk name TestDisk with 64MB space.
Binary file not shown.
Expand Up @@ -66,6 +66,16 @@
ReferencedContainer = "container:TmpDisk.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-name=Test"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-size=32"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand Down
33 changes: 33 additions & 0 deletions TmpDisk/AppDelegate.m
Expand Up @@ -35,6 +35,39 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application

// Check if TmpDisk was launched with command line args
NSArray *arguments = [[NSProcessInfo processInfo] arguments];

NSString *argName = nil;
NSString *argSize = nil;
// TODO: There's likely a better way to parse command line args
for (int i=0, n=[arguments count]; i<n; i++) {
NSString *s = [arguments objectAtIndex:i];

// We expect args in the format -argname=argval

NSArray *arg = [s componentsSeparatedByString:@"="];
if ([arg count] == 2) {
if ([[arg objectAtIndex:0] isEqualToString:@"-name"]) {
argName = [NSString stringWithString:[arg objectAtIndex:1]];
} else if ([[arg objectAtIndex:0] isEqualToString:@"-size"]) {
argSize = [NSString stringWithString:[arg objectAtIndex:1]];
}
}
}

if (argName != nil && argSize != nil) {

int dsize = [argSize intValue];
int size = (dsize * 1024 * 1000) / 512;

if(![[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"/Volumes/%@", argName] isDirectory:nil]) {
[TmpDiskManager createTmpDiskWithName:argName size:size autoCreate:NO onSuccess:nil];
}

}


if ([[NSUserDefaults standardUserDefaults] objectForKey:@"autoCreate"]) {

NSArray *autoCreateArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"autoCreate"];
Expand Down
14 changes: 14 additions & 0 deletions TmpDisk/Classes/AutoCreateManagerWindow.h
Expand Up @@ -5,6 +5,20 @@
// Created by Timothy Marks on 24/11/11.
// Copyright (c) 2011 Ink Scribbles Pty Ltd. All rights reserved.
//
// This file is part of TmpDisk.
//
// TmpDisk is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// TmpDisk is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TmpDisk. If not, see <http://www.gnu.org/licenses/>.

#import <Foundation/Foundation.h>

Expand Down
14 changes: 14 additions & 0 deletions TmpDisk/Classes/AutoCreateManagerWindow.m
Expand Up @@ -5,6 +5,20 @@
// Created by Timothy Marks on 24/11/11.
// Copyright (c) 2011 Ink Scribbles Pty Ltd. All rights reserved.
//
// This file is part of TmpDisk.
//
// TmpDisk is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// TmpDisk is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TmpDisk. If not, see <http://www.gnu.org/licenses/>.

#import "AutoCreateManagerWindow.h"

Expand Down
14 changes: 14 additions & 0 deletions TmpDisk/Classes/TmpDiskManager.h
Expand Up @@ -5,6 +5,20 @@
// Created by Timothy Marks on 22/11/11.
// Copyright (c) 2011 Ink Scribbles Pty Ltd. All rights reserved.
//
// This file is part of TmpDisk.
//
// TmpDisk is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// TmpDisk is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TmpDisk. If not, see <http://www.gnu.org/licenses/>.

#import <Foundation/Foundation.h>

Expand Down
14 changes: 14 additions & 0 deletions TmpDisk/Classes/TmpDiskManager.m
Expand Up @@ -5,6 +5,20 @@
// Created by Timothy Marks on 22/11/11.
// Copyright (c) 2011 Ink Scribbles Pty Ltd. All rights reserved.
//
// This file is part of TmpDisk.
//
// TmpDisk is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// TmpDisk is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TmpDisk. If not, see <http://www.gnu.org/licenses/>.

#import "TmpDiskManager.h"

Expand Down
4 changes: 2 additions & 2 deletions TmpDisk/TmpDisk-Info.plist
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.3</string>
<string>1.0.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0.3</string>
<string>1.0.4</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down

0 comments on commit 21da40d

Please sign in to comment.